I have a json file.
{"bla":"bla"}
{"bla":"bla"}
{"bla":"bla"}
{"bla":"bla"}
......
How can I format these into a valid json type, like:
[
{"bla":"bla"},
{"bla":"bla"},
{"bla":"bla"},
{"bla":"bla"},
......
{"bla":"bla"}
]
Insert comma after each {} except last one.
How can I do that in java?
Thanks.
PS: OK. This is a json file called “1.json” which I created from TCP response. I send some names to the server and I receive response and save as a file. Because all the data is like {“bal”:”bla”}{“bal”:”bla”}{“bal”:”bla”}{“bal”:”bla”}……
This is an invalid json structure that jQuery getJSON() couldn’t read it. So I want to parse it to a valid type.
If you are just needing to reformat that input (lines of JSON objects, one line each), then you dont really need to convert them into Java JSON objects, you can just read the file in and convert it on the fly to the new JSON string:
or something similar. Just note that this will only work if your JSON objects are defined on single lines not spread across multiples.
Hope this helps.