Pretty Print JSON in Python Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report JSON is a javascript notation of storing and fetching the data. Data is usually stored in JSON, XML or in some other database. It is a complete language-independent text format. To work with JSON data, Python has a built-in package called json. Note: For more information, refer to Read, Write and Parse JSON using Python Pretty Print JSON 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. Example 1: Python3 # Write Python3 code here import json json_data = '[{"Employee ID":1,"Name":"Abhishek","Designation":"Software Engineer"},' \ '{"Employee ID":2,"Name":"Garima","Designation":"Email Marketing Specialist"}]' json_object = json.loads(json_data) # Indent keyword while dumping the # data decides to what level # spaces the user wants. print(json.dumps(json_object, indent = 1)) # Difference in the spaces # near the brackets can be seen print(json.dumps(json_object, indent = 3)) Output: [ { "Employee ID": 1, "Name": "Abhishek", "Designation": "Software Engineer" }, { "Employee ID": 2, "Name": "Garima", "Designation": "Email Marketing Specialist" } ] [ { "Employee ID": 1, "Name": "Abhishek", "Designation": "Software Engineer" }, { "Employee ID": 2, "Name": "Garima", "Designation": "Email Marketing Specialist" } ] Time complexity: O(1) Auxiliary space: O(1) Example 2: Let's suppose we want to pretty-print the data from the JSON file. JSON File: Python3 import json # Opening JSON file f = open('myfile.json',) # returns JSON object as # a dictionary data = json.load(f) print(json.dumps(data, indent = 1) # Closing file f.close() Output: { "emp1": { "name": "Lisa", "designation": "programmer", "age": "34", "salary": "54000" }, "emp2": { "name": "Elis", "designation": "Trainee", "age": "24", "salary": "40000" } } Comment More infoAdvertise with us Next Article Pretty Print JSON in Python A AbhishekAgarwal4 Follow Improve Article Tags : Python Python-json Practice Tags : python Similar Reads Python - Pretty Print JSON JSON stands for JavaScript Object Notation. It is a format for structuring data. This format is used by different web applications to communicate with each other. In this article, we will learn about JSON pretty print What is JSON?JSON (JavaScript Object Notation) is a text-based data format that is 5 min read JSON Parsing Errors in Python JSON is a widely used format for exchanging data between systems and applications. Python provides built-in support for working with JSON data through its JSON module. However, JSON parsing errors can occur due to various reasons such as incorrect formatting, missing data, or data type mismatches.Th 6 min read Update JSON Key Name in Python Working with JSON data is a common task in Python, and there are various scenarios where you might need to update the key names within a JSON object. In this article, we will explore five different simple and generally used methods to achieve this task, accompanied by code examples. How to Update Js 3 min read json.load() in Python The full-form of JSON is JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called json. To use this feature, we import the json package in Pytho 3 min read json.loads() in Python JSON is a lightweight data format used for storing and exchanging data across systems. Python provides a built-in module called json to work with JSON data easily. The json.loads() method of JSON module is used to parse a valid JSON string and convert it into a Python dictionary. For example:Pythoni 4 min read Python Pandas - Flatten nested JSON It is general practice to convert the JSON data structure to a Pandas Dataframe as it can help to manipulate and visualize the data more conveniently. In this article, let us consider different nested JSON data structures and flatten them using inbuilt and custom-defined functions. Python Pandas.js 5 min read How to parse JSON in Ruby? JSON stands for JavaScript Object Notation. In the JSON the data is stored in the form of a key-value pair. we can parse the JSON file in various languages with the help of the respective modules available in the languages. Let's suppose when we want to parse a JSON file in the Python programming la 4 min read json.dump() in Python The full-form of JSON is JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called json . To use this feature, we import the json package in Pyth 6 min read orjson.JSONDecodeError in Python When working with JSON data in Python, errors may occur during decoding, especially if the data is malformed or incorrectly formatted. The orjson library, known for its speed and efficiency in handling JSON, provides a specific exception called orjson.JSONDecodeError to handle such situations. In th 3 min read json.dumps() in Python JSON is an acronym that stands for JavaScript Object Notation. Despite its name, JSON is a language agnostic format that is most commonly used to transmit data between systems, and on occasion, store data. Programs written in Python, as well as many other programming languages, can ingest JSON forma 6 min read Like