Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python JSON
Next article icon

Python JSON

Last Updated : 23 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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 object

Let'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) 

Output
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) 

Output
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.

JSON in Python

Introduction

  • What is JSON?
  • Data types in JSON
  • Working With JSON Data in Python
  • Read, Write and Parse JSON using Python

Reading and Writing JSON

  • Reading and Writing JSON to a File in Python
  • Read JSON file using Python
  • Append to JSON file using Python

Parsing JSON

  • How to Parse Data From JSON into Python?
  • How To Convert Python Dictionary To JSON?
  • Python – Convert JSON to string
  • Ways to convert string to json object
  • Convert JSON data Into a Custom Python Object

Serializing and Deserializing JSON

  • Serializing JSON in Python
  • json.dump() in Python
  • json.dumps() in Python
  • Python – Difference between json.dump() and json.dumps()
  • Deserialize JSON to Object in Python
  • json.load() in Python
  • json.loads() in Python
  • Difference Between json.load() and json.loads()
  • Encoding and Decoding Custom Objects in Python-JSON
  • Serialize and Deserialize complex JSON in Python

Conversion between JSON

  • Python – JSON to XML
  • Python – XML to JSON
  • Convert CSV to JSON using Python
  • Convert multiple JSON files to CSV Python
  • Convert Text file to JSON in Python
  • Saving Text, JSON and CSV to a File in Python

More operations JSON

  • JSON Formatting in Python
  • Pretty Print JSON in Python
  • Flattening JSON objects in Python
  • Check whether a string is valid json or not
  • Sort JSON by value

Next Article
Python JSON

A

abhishek1
Improve
Article Tags :
  • Python
  • JSON
  • Python-json
Practice Tags :
  • python

Similar Reads

    Python Modules
    Python Module is a file that contains built-in functions, classes,its and variables. There are many Python modules, each with its specific work.In this article, we will cover all about Python modules, such as How to create our own simple module, Import Python modules, From statements in Python, we c
    7 min read
    Python Arrays
    Lists in Python are the most flexible and commonly used data structure for sequential storage. They are similar to arrays in other languages but with several key differences:Dynamic Typing: Python lists can hold elements of different types in the same list. We can have an integer, a string and even
    9 min read
    asyncio in Python
    Asyncio is a Python library that is used for concurrent programming, including the use of async iterator in Python. It is not multi-threading or multi-processing. Asyncio is used as a foundation for multiple Python asynchronous frameworks that provide high-performance network and web servers, databa
    4 min read
    Calendar in Python
    Python has a built-in Python Calendar module to work with date-related tasks. Using the module, we can display a particular month as well as the whole calendar of a year. In this article, we will see how to print a calendar month and year using Python. Calendar in Python ExampleInput: yy = 2023 mm =
    2 min read
    Python Collections Module
    The collection Module in Python provides different types of containers. A Container is an object that is used to store different objects and provide a way to access the contained objects and iterate over them. Some of the built-in containers are Tuple, List, Dictionary, etc. In this article, we will
    13 min read
    Working with csv files in Python
    Python is one of the important fields for data scientists and many programmers to handle a variety of data. CSV (Comma-Separated Values) is one of the prevalent and accessible file formats for storing and exchanging tabular data. In article explains What is CSV. Working with CSV files in Python, Rea
    10 min read
    Python datetime module
    In Python, date and time are not data types of their own, but a module named DateTime in Python can be imported to work with the date as well as time. Python Datetime module comes built into Python, so there is no need to install it externally. In this article, we will explore How DateTime in Python
    14 min read
    Functools module in Python
    The functools module offers a collection of tools that simplify working with functions and callable objects. It includes utilities to modify, extend, or optimize functions without rewriting their core logic, helping you write cleaner and more efficient code.Let's discuss them in detail.1. Partial cl
    5 min read
    hashlib module in Python
    A Cryptographic hash function is a function that takes in input data and produces a statistically unique output, which is unique to that particular set of data. The hash is a fixed-length byte stream used to ensure the integrity of the data. In this article, you will learn to use the hashlib module
    5 min read
    Heap queue or heapq in Python
    A heap queue or priority queue is a data structure that allows us to quickly access the smallest (min-heap) or largest (max-heap) element. A heap is typically implemented as a binary tree, where each parent node's value is smaller (for a min-heap) or larger (for a max-heap) than its children. Howeve
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences