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.

🌐
ReqBin
reqbin.com › code › python › 0l6wsqxp › python-pretty-print-json-example
How do I pretty print JSON in Python?
To pretty print a JSON string in Python, you can use the json.dumps(indent) method of the built-in package named json. First, you need to use the json.loads() method to convert the JSON string into a Python object.
Discussions

How do you print json data in multiply lines?
Use the pprint module. from pprint import pprint response = requests.get(url) x = json.loads(response.text) pprint(x) (BTW json is just the vehicle; there's no such type as "json data". The data you have is just standard python lists and dictionaries.) Edit: the json module also has this feature: import json response = requests.get(url) x = json.loads(response.text) print(json.dumps(x, indent=2)) More on reddit.com
🌐 r/learnpython
10
5
December 4, 2021
JSON and Dictionary
The core of your answer is correct: JSON is some string representation of data dicts are objects in memory But your explanations are geting away from these facts. 1. Comparing notation dicts are not strings! You say that dicts are represented by "curly braces" . So you are comparing json with dict representation, not dicts themselves. my_dict = dict('name' = 'eagle221b', 'platform' = 'reddit') This is another representation of dicts, that does not look like JSOn at all. Also you are saying "curly braces"in JSON are objects. No they are representations of objects. This makes a great difference when working with them. 2. the power of dicts So let me create another example again: my_list = [] my_dict1 = {'my_list': my_list} my_dict2 = {'my_list': my_list} my_list.append('foo') The last command has not changed any of the dicts, but if you print them, you will see the representation has changed. Also about the values: you can store objects or even functions in them. A value in dicts is just a memory pointer. (and yes, any number in python is an object) Conclusion They both are completly different things that both are based on a key value principle. But one is a text, one is memory and therefore very different. More on reddit.com
🌐 r/Python
49
250
September 27, 2020
Manipulating JSON dictionaries

I think you are saying that you have JSON-encoded data, and you want to pretty print it.

In that case, use this:

import json
with open("myfile.json") as I:
    print(json.dumps(json.load(I), indent=1))

All that does is load the JSON data into a Python dictionary, and then re-dumps it as a string with pretty indentation.

I'm not sure that you're clear on your terminology, though, which may cause a lot of confusion for you down the line. A dictionary is the same as an object in Javascript: a mapping of keys to values. JSON stands for Javascript Object Notation, meaning that it's an encoding format for Javascript Objects which conveniently matches the literal syntax for Javascript Objects, and some types of Python Dictionary. But, JSON is just the encoding format, the underlying data is termed an Object or Dictionary, or whatever, depending on the language.

More on reddit.com
🌐 r/learnpython
8
7
December 21, 2012
Top answer
1 of 1
1
Explain Python Pretty Print JSONJSON (JavaScript Object Notation) is a widely used data format for data interchange. It's human-readable and machine-friendly, making it a popular choice for configuration files, APIs, and data storage. Sometimes, when working with JSON data in Python, you might encounter large or complex JSON structures that are challenging to read. That's where Python's "pretty print" functionality comes into play.Pretty printing is the process of formatting JSON data to make it more legible and visually appealing to humans. Python provides a built-in module called `json` that includes a `dumps()` method. Using this method with specific parameters lets you easily print JSON data.In this article, we'll explore using Python's `json.dumps()` method to pretty print JSON data.PrerequisitesBefore we dive into pretty printing JSON in Python, ensure you have Python installed on your system. You can download it from the official Python website: https://www.python.org/downloads/What is JSON?JSON is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. It's often used to transmit data between a server and a web application or between different parts of an application.JSON data is represented as a collection of key-value pairs, similar to Python dictionaries. Here's a simple example:json{    "name": "John Doe",    "age": 30,    "city": "New York"}In Python, JSON data is typically converted to dictionaries or lists using the `json` module, making it easy to work with.Using `json.dumps()` for Pretty PrintingPython's `json.dumps()` function converts a Python object into a JSON formatted string. By default, the JSON output is compact and not very human-readable. You can use the `indent` parameter to make it more readable.Here's the basic syntax of `json.dumps()` with the `indent` parameter:import jsonpretty_json = json.dumps(your_data, indent=4) `your_data`: This is the Python object (e.g., dictionary or list) that you want to convert to JSON. `indent=4`: This parameter specifies the number of spaces to use for indentation in the resulting JSON string. In this case, we use 4 spaces to make it nicely formatted.Example: Pretty Printing JSONLet's see an example of pretty printing JSON in Python:import json# Sample JSON datadata = {    "name": "John Doe",    "age": 30,    "city": "New York",    "skills": }# Pretty print the JSON datapretty_json = json.dumps(data, indent=4)# Print the pretty JSONprint(pretty_json)When you run this code, it will produce the following nicely formatted JSON output:json{    "name": "John Doe",    "age": 30,    "city": "New York",    "skills": }As you can see, the JSON data is now structured with proper indentation, making it much easier to read and understand.Use Cases for Pretty PrintingPretty printing JSON is particularly helpful in scenarios where: Debugging: When you're working with JSON data and need to debug or inspect it, pretty printing makes it more human-readable and helps you identify issues more easily. Logging: If you're logging JSON data in your application, pretty print formatting can make your log files more organized and user-friendly. Configuration Files: Pretty printing is beneficial when dealing with configuration files in JSON format. It ensures that configuration settings are neatly organized. API Development: When building or consuming JSON APIs for data exchange, pretty printing can assist in documenting and testing the API endpoints.ConclusionPython's `json.dumps()` method with the `indent` parameter is a valuable tool for pretty much printing JSON data. It allows you to format JSON in a human-readable way, making it easier to work with, debug, and understand. Whether you're developing web applications, working with configuration files, or dealing with API data, pretty printing JSON can significantly improve your workflow and code readability.
🌐
iO Flood
ioflood.com › blog › python-json-pretty-print
Python JSON Pretty Print | Guide (With Examples)
February 1, 2024 - The json.dumps() function takes two parameters: the data you want to convert, and the indent parameter. The indent parameter is optional, but it’s what allows us to pretty print the JSON data.
🌐
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
🌐
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 …
Find elsewhere
🌐
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 a presentable format.
🌐
Vertabelo Academy
academy.vertabelo.com › course › python-json › writing-json-files › writing-to-json-file › jsondumps-options-the-indent
How to Read and Write JSON Files in Python | Learn Python | Vertabelo Academy
We have saved some information in a Python object named data. Using json.dumps(), convert it to a string. Set the indent option to 4. Print the result.
🌐
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)
🌐
MLJAR
mljar.com › docs › python-pretty-print-json
Pretty print JSON in Python
Pretty print JSON or dict objects in Python. It is much easier to understand JSON objects that has nice indentation.
🌐
TutorialsPoint
tutorialspoint.com › pretty-print-json-in-python
Pretty Print JSON in Python
July 25, 2023 - 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.
🌐
Reddit
reddit.com › r/learnpython › how do you print json data in multiply lines?
r/learnpython on Reddit: How do you print json data in multiply lines?
December 4, 2021 -

Currently trying to get some data from a url which shows in json format, i can get the data, however when i print it, it just shows in 1 long line of text which isnt what i want. i want the text to be split into multiply lines like when you add \n to strings. (i know its normally not good to do except Exceptions, its just there while i get the other part to work, also the entire def is in a class)

Here is what i currently have. I havent work much with json data before which is why im stuck at what exactly to do.

def info(self):
      try:
            url = [url]
            response = requests.get(url)
            x = json.loads(response.text)
            lore = str(x['data'][input_champion]['lore'])
            print('Getting champion info, please wait')
            time.sleep(5)
            print(f'lore:  {lore}')
            time.sleep(0.5)

      except Exception as e:
            time.sleep(5)
🌐
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
If you have a JSON string, you can parse it by using the json.loads() method. The result will be a Python dictionary.
🌐
Programiz
programiz.com › python-programming › json
Python JSON: Read, Write, Parse JSON (With Examples)
In this tutorial, you will learn to parse, read and write JSON in Python with the help of examples. Also, you will learn to convert JSON to dict and pretty print it.
🌐
DataCamp
datacamp.com › tutorial › json-data-python
Python JSON Data: A Guide With Examples | DataCamp
December 3, 2024 - IoT devices often generate large amounts of data, which can be stored and transmitted between sensors and other devices more efficiently using JSON. python_obj = { "name": "John Doe", "age": 30, "email": "john.doe@example.com", "is_employee": True, "hobbies": [ "reading", "playing soccer", "traveling" ], "address": { "street": "123 Main Street", "city": "New York", "state": "NY", "zip": "10001" } } print(python_obj) In this example, we have a JSON object that represents a person.
🌐
Firecrawl
docs.firecrawl.dev › introduction
Quickstart | Firecrawl
Python · Node · CLI · Copy · from firecrawl import Firecrawl firecrawl = Firecrawl(api_key="fc-YOUR-API-KEY") results = firecrawl.search( query="firecrawl", limit=3, ) print(results) Response · SDKs will return the data object directly. cURL will return the complete payload. JSON ·
🌐
Google
google.github.io › adk-docs › agents › llm-agents
LLM agents - Agent Development Kit (ADK)
Output Schema --- import json # Needed for pretty printing dicts import asyncio from google.adk.agents import LlmAgent from google.adk.runners import Runner from google.adk.sessions import InMemorySessionService from google.genai import types from pydantic import BaseModel, Field # --- 1.
🌐
Langchain
reference.langchain.com › python › langchain-core
langchain_core | LangChain Reference
Print text with highlighting and no end characters. ... An individual iterator of a tee. ... Utility batching function for async iterables. ... Generate a UUID from a Unix timestamp in nanoseconds and random bits. ... An individual iterator of a .tee. ... Utility batching function. ... Parse a JSON string that may be missing closing braces.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to pretty print a json file in python?
How to Pretty Print a JSON file in Python? - Spark By {Examples}
May 31, 2024 - The dumps() from the json module & pprint() from the pprint module are used to pretty print a JSON file in Python, JSON data is often stored in a