Answers for "pretty print json"

11

python print pretty json

import json

json_data = '[{"ID":10,"Name":"Pankaj","Role":"CEO"},' \
            '{"ID":20,"Name":"David Lee","Role":"Editor"}]'

json_object = json.loads(json_data)

json_formatted_str = json.dumps(json_object, indent=2)

print(json_formatted_str)
Posted by: Guest on April-30-2020
2

python write to json with indent

import json

# alphabetic dictionary
json_data = {hex(k): chr(k) for k in range(ord('a'), ord('z') + 1)}
# to file
with open("my_json.json", "w") as file:
    json.dump(json_data, file, indent=4, sort_keys=True)
Posted by: Guest on June-29-2020
6

json stringify pretty

JSON.stringify(jsonobj,null,'\t')
Posted by: Guest on January-31-2020
2

json.stringify pretty

var str = JSON.stringify(obj, null, 2); // spacing level = 2
Posted by: Guest on June-23-2020
4

python json.dumps pretty print

json.dumps(x, indent=4)
Posted by: Guest on September-23-2020
1

print json pretty linux

echo '{"foo": "lorem", "bar": "ipsum"}' | python -m json.tool
Posted by: Guest on June-30-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language