>>> import json
>>> a = json.loads('{"X":"value1","Y":"value2","Z":[{"A":"value3","B":"value4"}]}')
>>> a
{'Y': 'value2', 'X': 'value1', 'Z': [{'A': 'value3', 'B': 'value4'}]}
>>> a["Z"][0]["A"]
'value3'
Answer from Tim Pietzcker on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-pretty-print-json
How to Pretty Print JSON in Python | DigitalOcean
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.
🌐
Stack Overflow
stackoverflow.com › questions › 44169258 › printing-json-elements
python - Printing JSON elements - Stack Overflow
May 25, 2017 - Because those keys do not exist at that hierarchy within the JSON. They exist within the dictionary against the "location" key. You'd want to use: ... Sign up to request clarification or add additional context in comments. ... Because those exist in the "location" sub-dictionary. You would need something like this: ... for element in response_data['businesses']: id = element['id'] name = element['name'] city = element['location']['city'] zip_code = element['location']['zip_code'] state = element['location']['state'] display_address = element['location']['display_address'] latitude = element['coordinates']['latitude'] longitude = element['coordinates']['longitude'] phone = element['phone'] print id, name, city, zip_code, state, display_address, latitude, longitude, phone
Address: 3 place du Président Thomas Wilson, Toulouse
🌐
CodeSpeedy
codespeedy.com › home › how to print particular json value in python
How to print particular JSON value in Python - CodeSpeedy
September 28, 2022 - import json fp=open("example_2.json") ... particular value from a json file. print("First Print") print(data['quiz']['sport']) print("Second Print") print(data['quiz']['sport']['q1']['options']) ... In our code, we have first imported ...
🌐
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.
🌐
datagy
datagy.io › home › python posts › pretty print a json file in python (6 methods)
Pretty Print a JSON File in Python (6 Methods) • datagy
August 31, 2022 - Learn how to use Python to pretty print a JSON object, including from a file, from an API, and how to save the pretty output to a file.
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.7 documentation
The json module always produces str objects, not bytes objects, therefore fp.write() must support str input. skipkeys (bool) – If True, keys that are not of a basic type (str, int, float, bool, None) will be skipped instead of raising a TypeError. Default False. ensure_ascii (bool) – If True (the default), the output is guaranteed to have all incoming non-ASCII and non-printable characters escaped.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-pretty-print-json-in-python
How to Pretty Print JSON in Python
April 14, 2023 - This module provides a dumps() function that can serialize Python objects into a JSON formatted string. By default, this function produces a JSON string without any formatting, but we can use the indent parameter to specify the number of spaces to use for indentation. Here's an example of how to pretty print JSON in Python:
🌐
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.
Find elsewhere
🌐
Python Forum
python-forum.io › thread-32887.html
Printing a specific line from a JSON
Hi all! I'm new to Python and programming, so please bear with me :-) I'm doing a project at home in my spare time where I want to get the next departure to the nearest bus station. I have got a API key and have the right enpoint set up, this is how...
🌐
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 ...
🌐
DEV Community
dev.to › pineapple_26 › json-pretty-print-using-python-with-examples-12ha
JSON Pretty Print Using Python - With Examples - DEV Community
November 20, 2025 - The easiest way to pretty print JSON in Python is using json.dumps() with the indent parameter.
🌐
Programiz
programiz.com › python-programming › json
Python JSON: Read, Write, Parse JSON (With Examples)
To work with JSON (string, or file containing JSON object), you can use Python's json module. You need to import the module before you can use it. ... The json module makes it easy to parse JSON strings and files containing JSON object. You can parse a JSON string using json.loads() method.
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 52996227 › python-print-all-values-of-json-objects
Python - print all values of JSON objects - Stack Overflow
October 26, 2018 - I'm using python to get the values of the publications elements. ... import json with open('derp.json') as f: data = json.load(f) for i in range (0, len (data['authors'])): print data['authors'][i]['name']+data['authors'][i]['publications']
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - If you want linebreaks in your JSON string, then you can set indent to 0 or provide an empty string. Although probably less useful, you can even provide a negative number as the indentation or any other string. More commonly, you’ll provide values like 2 or 4 for indent: ... >>> print(json.dumps(dog_friend, indent=2)) { "name": "Mitch", "age": 6.5 } >>> print(json.dumps(dog_friend, indent=4)) { "name": "Mitch", "age": 6.5 }
🌐
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, and then pretty-prints the JSON data with zero indentation, making it compact and less readable.