Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pretty JSON Formatting in IPython Notebook

Is there an existing way to get json.dumps() output to appear as "pretty" formatted JSON inside ipython notebook?

like image 285
Kyle Brandt Avatar asked Sep 18 '13 13:09

Kyle Brandt


People also ask

How do I beautify JSON output in Python?

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.

How do I display pretty JSON?

Use JSON. stringify(obj) method to convert JavaScript objects into strings and display it. Use JSON. stringify(obj, replacer, space) method to convert JavaScript objects into strings in pretty format.


1 Answers

json.dumps has an indent argument, printing the result should be enough:

print(json.dumps(obj, indent=2)) 
like image 68
filmor Avatar answered Oct 06 '22 05:10

filmor