JSON - differentiate data

Hello everyone! I have a problem of differentiating JSON from non-JSON input. For example, I speak with another program via a pipe, most of the time it returns the valid JSON data,
but sometimes it returns just a newline-separated list, e.g.

[{key:value, ...}]
[{key:value, ...}]

I use this code to process the output:

read_result(Out, Json) :-
	read_string(Out, "", "", _, String),
	atom_json_dict(String, Json, []).

send_command(R, Command, Json) :-
	write(R.in, Command),
	nl(R.in),
	flush_output(R.in),
	read_result(R.out, Json).

(See https://github.com/radare/radare2-r2pipe/blob/dbb2e2c9a7dcaf6af3ecbd684ad59e880bde47a6/prolog/r2pipe.pl for more context)
As you can see if the program output is valid JSON - everything is fine. But if the output is the sequence of that JSONs it processes only the first one. The question is - how to differentiate between these kinds of the outputs on the fly and process accordingly?

See the end_of_file option for json_read_dict/3. Now, assuming you can read up to end-of-file, just read until json_read_dict/3 returns the end-of-file indicator. You need a quite recent copy of SWI-Prolog for this option.