T
T
Tannenfels2020-09-01 15:30:02
Java
Tannenfels, 2020-09-01 15:30:02

How to separate JSON from the rest of a text file?

There is a fairly long log file, in which, mixed with regular logs, there are logs in JSON. I need to extract one single JSON from these logs, it is recognized by some character combination (always the same) before the beginning of this JSON, but not part of the json document. In this case, it is desirable to discard everything that comes after this json. I'm new to Java, can you tell me the best way to do this?

PS I forgot to add, the required json occupies one line, and the sequence by which it can be found is at the beginning of this line.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-09-01
@sergey-gornostaev

Find this sequence of characters, skip it, and start reading data until there are as many closing curly braces as there are opening ones.

S
Sergey Vodakov, 2020-09-01
@WaterSmith

PS I forgot to add, the required json occupies one line, and the sequence by which it can be found is at the beginning of this line.

If so, then take part of the string, starting from the first character after the key sequence, and up to the end of the string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question