Open philipashlock opened 9 years ago
Yes, that makes sense for files on disk. I wanted to add some canonical examples of "jsonl2json" that would look something like this.
Just wondering why you choose to have an object at the outermost level instead of just a list?
The object at the outermost level was only included to demonstrate that the first and last lines could have more structure than just opening and closing brackets.
How about this:
sed -e'1s/^/[/' -e's/$/,/' -e'$s/,$/]/'
[{"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]},
{"name": "Alexa", "wins": [["two pair", "4♠"], ["two pair", "9♠"]]},
{"name": "May", "wins": []},
{"name": "Deloise", "wins": [["three of a kind", "5♣"]]}]
The line numbers match this way, and converting back is even simpler:
sed -e'1s/\[//' -e's/.$//'
There is JSONL on one side, and then JSON on the other. We can define a "standard" way to convert JSONL to JSON, and build tool around it, but let not mix up both and say that some JSON could be JSONL if formatted in a specific way. So I'd proposed to rename, or reclassify the issue, as defining the standard way to convert JSONL to JSON instead.
Perhaps it would also be useful to define an alternate form of jsonlines where the file would still be valid json. I'll refer to this alternate as jsonnewlines. If you wanted to treat a jsonnewlines file as a jsonlines file, you would simply ignore the first and last line of the file as well as the comma before each line separator.
For example, this jsonlines file:
Would look like this as jsonnewlines:
It seems like this would still let you get the benefits of jsonlines while also allowing for the possibility of treating the file as JSON in whole.