Use the indent= parameter of json.dump() or json.dumps() to specify how many spaces to indent by:

>>> import json
>>> your_json = '["foo", {"bar": ["baz", null, 1.0, 2]}]'
>>> parsed = json.loads(your_json)
>>> print(json.dumps(parsed, indent=4))
[
    "foo",
    {
        "bar": [
            "baz",
            null,
            1.0,
            2
        ]
    }
]

To parse a file, use json.load():

with open('filename.txt', 'r') as handle:
    parsed = json.load(handle)
Answer from Blender on Stack Overflow
Top answer
1 of 15
3096

Use the indent= parameter of json.dump() or json.dumps() to specify how many spaces to indent by:

>>> import json
>>> your_json = '["foo", {"bar": ["baz", null, 1.0, 2]}]'
>>> parsed = json.loads(your_json)
>>> print(json.dumps(parsed, indent=4))
[
    "foo",
    {
        "bar": [
            "baz",
            null,
            1.0,
            2
        ]
    }
]

To parse a file, use json.load():

with open('filename.txt', 'r') as handle:
    parsed = json.load(handle)
2 of 15
500

You can do this on the command line:

python3 -m json.tool some.json

(as already mentioned in the commentaries to the question, thanks to @Kai Petzke for the python3 suggestion).

Actually python is not my favourite tool as far as json processing on the command line is concerned. For simple pretty printing is ok, but if you want to manipulate the json it can become overcomplicated. You'd soon need to write a separate script-file, you could end up with maps whose keys are u"some-key" (python unicode), which makes selecting fields more difficult and doesn't really go in the direction of pretty-printing.

You can also use jq:

jq . some.json

and you get colors as a bonus (and way easier extendability).

Addendum: There is some confusion in the comments about using jq to process large JSON files on the one hand, and having a very large jq program on the other. For pretty-printing a file consisting of a single large JSON entity, the practical limitation is RAM. For pretty-printing a 2GB file consisting of a single array of real-world data, the "maximum resident set size" required for pretty-printing was 5GB (whether using jq 1.5 or 1.6). Note also that jq can be used from within python after pip install jq.

🌐
DigitalOcean
digitalocean.com › community › tutorials › python-pretty-print-json
How to Pretty Print JSON in Python | DigitalOcean
September 16, 2025 - Learn how to pretty print JSON in Python using built-in tools like json.dumps() and pprint to improve readability and debug structured data efficiently.
Discussions

Pretty print JSON from URL
I've not done a lot in this space but something I have tried in the past with JSON's is to convert to a pandas DataFrame. I'm not sure if this is exactly what you are after, but the following stackoverflow post may help: https://stackoverflow.com/questions/21104592/json-to-pandas-dataframe More on reddit.com
🌐 r/learnpython
13
2
August 27, 2021
How to output preview of JSON file data structure?
Have you considered using pprint from pprint module? It eases the printing on the eyes. Then I would just do pprint(data) More on reddit.com
🌐 r/learnpython
7
13
November 15, 2021
formatting json output in Python
json.dumps(obj, indent=2, sort_keys=False) More on reddit.com
🌐 r/learnpython
16
52
May 12, 2022
Beautify JSON in Emacs

You're using interactive wrong. Command should take beg and end args and process them apropriately in the interactive form. E.g. "*r"

More on reddit.com
🌐 r/emacs
4
16
February 18, 2013
🌐
ReqBin
reqbin.com › code › python › 0l6wsqxp › python-pretty-print-json-example
How do I pretty print JSON in Python?
The json.dumps() method takes a number of parameters, including the "indent" level for the JSON arrays, which will be used to pretty-print the JSON string. If the json.dumps() indentation parameter is negative 0, or an empty string, then there ...
🌐
W3Schools
w3schools.com › python › gloss_python_format_json.asp
Python Format JSON
json.dumps(x, indent=4, separators=(". ", " = ")) Try it Yourself » · Python JSON Tutorial JSON Parse JSON Convert into JSON Sort JSON
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - Free Bonus: Click here to download the free sample code that shows you how to work with JSON data in Python. When you pass in hello_frieda.json to json.tool, then you can pretty print the content of the JSON file in your terminal.
🌐
Make Tech Easier
maketecheasier.com › home › linux › how to pretty print a json file in python
How to Pretty Print a JSON File in Python - Make Tech Easier
June 24, 2022 - Also read: How to Utilize Python for Basic Linux System Administration and Networking Tasks · Below, we show you how to pretty print a JSON file in Python. For our examples, we use NeoVim and the built-in :term command.
Find elsewhere
🌐
JSON Formatter
jsonformatter.org › c47f9c
python
JSON Example with all data types including JSON Array. Python Pretty Print JSON · Read JSON File Using Python · Validate JSON using PHP · Python Load Json From File · Online JSON Formatter and Online JSON Validator provide JSON converter tools to convert JSON to XML, JSON to CSV, and JSON to YAML also JSON Editor, JSONLint, JSON Checker, and JSON Cleaner.
🌐
LornaJane
lornajane.net › posts › 2013 › pretty-printing-json-with-pythons-json-tool
Pretty-Printing JSON with Python’s JSON Tool | LornaJane
I’ve been using http://www.jsonprettyprint.net if I just needed something quick when playing around with different API results. ... Oh that looks useful, thanks for sharing! ... 7 year glitch! I just stumbled across this post when searching something like ‘lorna http tools’ to recap on your stimulatingly super presentation at the virtual Python North West Meetup yesterday!
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pretty-print-json
Python - Pretty Print JSON - GeeksforGeeks
July 23, 2025 - This code reads JSON data from ... module. The pprint module is used to pretty-print the JSON data with specific formatting options like an indentation of 2, a line width of 30 characters, and compact representation...
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to prettyprint a json file with python?
How to PrettyPrint a JSON File Using Python?
December 13, 2022 - Note: Learn more about working with Python strings by referring to our article on how to substring a string in Python. Use the json.tool to PrettyPrint JSON files directly in the terminal. Use the following command format: ... The JSON file contents print to the output with indentation level four.
🌐
TutorialsPoint
tutorialspoint.com › pretty-print-json-in-python
Pretty Print JSON in Python
July 25, 2023 - It takes a single parameter, data, which is expected to be a JSON string. The purpose of this function is to parse the JSON data, format it in a human-readable way, and print the result. ... The json.loads function is used to parse the JSON string data and convert it into a Python object.
🌐
Kodeclik
kodeclik.com › pretty-print-json-python
How to pretty print a JSON object in Python
October 27, 2025 - To pretty print JSON in Python use the json module and the dumps function in it with a specified level of indentation.
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
JSON is text, written with JavaScript object notation. Python has a built-in package called json, which can be used to work with JSON data.
🌐
Reddit
reddit.com › r/learnpython › pretty print json from url
r/learnpython on Reddit: Pretty print JSON from URL
August 27, 2021 -

Hello Everyone,

I've hit a frustrating wall and after much googling I took a deep breath and felt the best approach was to ask you all for advice.

I'm making a very simple script and need assistance with what tool I should use to move forward.

Step 1: Fetch the URL Step 2: Make the JSON pretty. Such as a top-down listing of Title and URL only.

import requests

#make the URL call
page = requests.get('http://gleamlist.com:5000/api')
#verify the page has content - just for testing.
print(page.content)

I've tried using the json module but confuse myself and I've thought maybe BS4 would help but also confuse myself. I believe JSON is basically a dictionary and I want to parse out the info. Could anyone assist me with some tips or a specific topic to research and implement please?

🌐
Codingem
codingem.com › home › python pretty print json
Python Pretty Print JSON [with 3 Examples] - codingem.com
January 23, 2023 - Python pretty-printed JSON has indentations, spacings, and separators for your convenience. To pretty-print, call json.dumps(indent,separator)
🌐
Jsontotable
jsontotable.org › blog › python › python-pretty-print-json
Python Pretty Print JSON - Format JSON with Indentation (2025) | JSON to Table Converter
January 16, 2025 - Quick Answer: Use json.dumps(data, indent=2) to pretty print JSON with 2-space indentation in Python.
🌐
Python
docs.python.org › 3 › library › pprint.html
pprint — Data pretty printer
Source code: Lib/pprint.py The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the interpreter. If the formatted struc...
🌐
Codeblogmoney
codeblogmoney.com › json-pretty-print-using-python
JSON Pretty Print using Python- with Examples
May 25, 2018 - Some time for debugging purpose, we need to see beautified JSON data to understand and to Debug. This article will help to pretty print JSON data. There are two examples in the post. ... Here is the explanation for the code. ... This is a JSON library available in python to convert Python object from JSON string or from JSON file.