I've a file with a sequence of JSON element:
{ element0: "lorem", value0: "ipsum" } { element1: "lorem", value0: "ipsum" } ... { elementN: "lorem", value0: "ipsum" }
Is there a shell script to format JSON to display file content in a readable form?
I've seen this post, and I think is a good starting point!
My idea is to iterate rows in the file and then:
while read row; do echo ${row} | python -mjson.tool; done < "file_name"
Does anyone have any other ideas?
Pretty printing is a form of stylistic formatting including indentation and colouring. JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write and for machines to parse and generate. The official Internet media type for JSON is application/json .
Write Pretty Print JSON data to file To write a Python object as JSON formatted data into a file, json. dump() method is used. Like json. dumps() method, it has the indents and separator parameters to write beautified JSON.
Pipe the results from the file into the python json tool 2.6 onwards
python -m json.tool < 'file_name'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With