jq on non-well-formed JSON file

-1

So, a program I'm using dumped its data in a quasi-JSON like this:

{"id": "A0001", "weight": 10.5, "category": "A"}
{"id": "A0002", "weight": 8.0, "category": "A"}
{"id": "A0001", "weight": 22.3, "category": "B"}

As you can see, it has JSON dictionary per line instead of wrapped in a list.

Can jq handle this kind of malformed JSON?

pepoluan

Posted 2019-02-12T03:13:55.423

Reputation: 962

Answers

0

you could do it w/o jq, just using unix cli:

bash $ echo [ $(<file.json paste -s -d, -) ]
[ {"id": "A0001", "weight": 10.5, "category": "A"},{"id": "A0002", "weight": 8.0, "category": "A"},{"id": "A0001", "weight": 22.3, "category": "B"} ]
bash $ 

the resulting output is a valid JSON.

Dmitry

Posted 2019-02-12T03:13:55.423

Reputation: 1