1

Is there a way to convert JSONL to JSON in Linux with the full JSONL file depth? I found some methods based on jq but they don't work with full depth of JSONL file

Andrea993
  • 663
  • 1
  • 10
  • 23

2 Answers2

0

I am quite confused as to what you want to do. But when it comes to jq, normally I process things line by line, with each line being an atomic JSON object. Something like

cat file | jq some-options 'some commands' > output.txt

Sometimes I get the output in tsv format and pipe it into awk. jq is very friendly with line-by-line objects.

To convert a large JSON list into line by line format, just parse the large object in any programming language, and serialize the inner objects back to json line by line.

But if you have already parsed the large object, I suggest you do the required processing you want to do in jq directly, without serializing the inner objects back...

Patrick the Cat
  • 2,138
  • 1
  • 16
  • 33
0

Would something like this work?

#!/bin/sh
echo "[" >$1.json
perl -pe 's/$/,/' <$1 >>$1.json
echo "]" >>$1.json
L3viathan
  • 26,748
  • 2
  • 58
  • 81