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
🌐
JSON Formatter
jsonformatter.org › json-pretty-print
Best JSON Pretty Print Online
Best JSON Pretty Print tool to Make Pretty JSON and JSON Print in color and Save and Share Online.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pretty-print-json
Python - Pretty Print JSON - GeeksforGeeks
July 23, 2025 - The code takes a JSON string containing student records, parses it into a Python data structure, then pretty-prints the JSON data with proper indentation for improved readability.
Top answer
1 of 15
3095

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.

🌐
JSONLint
jsonlint.com › json-pretty-print
JSON Pretty Print - Format & Beautify JSON Online | JSONLint | JSONLint
Pretty print JSON instantly with our free online formatter. Customize indentation, sort keys, and beautify minified JSON. No signup required.
🌐
Prettier
prettier.io
Prettier · Opinionated Code Formatter · Prettier
Try It OnlineInstall Prettier · Limited edition tshirts are now available to buy! $10 per tshirt goes to maintain the project. An opinionated code formatter · Supports many languages · Integrates with most editors · Has few options » · Your code is formatted on save · No need to discuss style in code review · Saves you time and energy · And more » · JavaScript · JSX · Flow · TypeScript · JSON ·
🌐
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.
🌐
JSON Formatter
jsonformatter.org › c47f9c
python
This JSON online formatter can also work as JSON Lint.
🌐
JSON Formatter
jsonformatter.curiousconcept.com
JSON Formatter & Validator
The JSON Formatter & Validator beautifies and debugs JSON data with advanced formatting and validation algorithms.
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › how-to-pretty-print-json-in-python
How to Pretty Print JSON in Python
April 14, 2023 - In this article, we will explore how to pretty print JSON in Python using built-in and third-party libraries.
🌐
GeeksforGeeks
geeksforgeeks.org › python › pretty-print-json-in-python
Pretty Print JSON in Python - GeeksforGeeks
July 12, 2025 - Whenever data is dumped into Dictionary using the inbuilt module "json" present in Python, the result displayed is same as the dictionary format. Here the concept of Pretty Print Json comes into picture where we can display the JSON loaded into ...
🌐
ReqBin
reqbin.com › code › python › 0l6wsqxp › python-pretty-print-json-example
How do I pretty print JSON in Python?
In this Python Pretty Print JSON example, we load a minified JSON string and pretty print it using json.dumps() method. Click Execute to run the Python Pretty Print JSON example online and see result.
🌐
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...
🌐
Code Beautify
codebeautify.org › python-formatter-beautifier
Python Formatter and Beautifier
Best Python Formatter will help to format, beautify, minify, compact Python code, string, text. Format, Save, Share
🌐
Hako IT
hakoit.com › portrait › ➭ modern pretty json formatter & highlighter – format, validate, and download json easily
➭ Modern Pretty JSON Formatter & Highlighter – Format, Validate, and Download JSON Easily - Hako IT
June 25, 2025 - Using the Modern JSON Formatter by HakoIT, simply paste your JSON, select indentation (2 or 3 spaces), and click “Format JSON” to get a clean, readable output. In Python, use json.dumps(data, indent=2) to format JSON, or use the Modern JSON ...
🌐
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?

🌐
Better Stack
betterstack.com › community › questions › how-to-print-json-file-in-python
How to Prettyprint a Json File in Python? | Better Stack Community
You can pretty print a JSON file in Python using the json module's loads() function to parse the JSON data, and then the json.dumps() function with the indent parameter to output it in a readable format.
🌐
Medium
medium.com › @blogshub4 › how-to-pretty-print-a-json-string-in-python-98a85f99ecb4
How to Pretty Print a JSON String in Python | by Blogshub | Medium
December 22, 2024 - How to Pretty Print a JSON String in Python Pretty-printing JSON strings in Python is simple with the help of the built-in json module. By using the json.dumps() method with an indentation parameter …
🌐
Python Guides
pythonguides.com › python-pretty-print-json
How To Pretty Print JSON In Python
August 12, 2025 - This is my go-to method for pretty printing JSON in Python. Python’s json.dumps() function with the indent parameter creates beautifully formatted output. Let me show you how I used this recently when working with customer order data from a fictional online bookstore:
🌐
Mkyong
mkyong.com › home › web › how to pretty print json output with curl
How to Pretty Print JSON output with cURL - Mkyong.com
April 24, 2024 - curl -s https://api.cloudflare.com/client/v4/ | json_pp { "errors" : [ { "code" : 7000, "message" : "No route for that URI" } ], "messages" : [], "result" : null, "success" : false } If we have Python installed, we can use the Python’s built-in JSON tool python -m json.tool or python3 -m json.tool to format or pretty print JSON output.