Last Updated : 23 Jul, 2025
Python JSON JavaScript Object Notation is a format for structuring data. It is mainly used for storing and transferring data between the browser and the server. Python too supports JSON with a built-in package called JSON. This package provides all the necessary tools for working with JSON Objects including parsing, serializing, deserializing and many more.
Let's see a simple example where we convert the JSON objects to Python objects and vice versa.
Convert from JSON to Python objectLet's see a simple example where we convert the JSON objects to Python objects. Here, json.loads() method can be used to parse a valid JSON string and convert it into a Python Dictionary.
Python
import json
# JSON string
emp = '{"id":"09", "name": "Nitin", "department":"Finance"}'
print("This is JSON", type(emp))
print("\nNow convert from JSON to Python")
# Convert string to Python dict
d = json.loads(emp)
print("Converted to Python", type(d))
print(d)
This is JSON <class 'str'> Now convert from JSON to Python Converted to Python <class 'dict'> {'id': '09', 'name': 'Nitin', 'department': 'Finance'}Convert from Python object to JSON
Let's see a simple example where we convert Python objects to JSON objects. Here json.dumps() function will convert a subset of Python objects into a JSON string.
Python
import json
# JSON string
d = {'id': '09', 'name': 'Nitin', 'department': 'Finance'}
print("This is Python", type(d))
print("\nNow Convert from Python to JSON")
# Convert Python dict to JSON
obj = json.dumps(d, indent=4)
print("Converted to JSON", type(obj))
print(obj)
This is Python <class 'dict'> Now Convert from Python to JSON Converted to JSON <class 'str'> { "id": "09", "name": "Nitin", "department": "Finance" }JSON in Python
This JSON Tutorial will help you learn the working of JSON with Python from basics to advance, like parsing JSON, reading and writing to JSON files and serializing and deserializing JSON using a huge set of JSON programs.
IntroductionRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4