Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python Modules
Next article icon

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
importjson# JSON stringemp='{"id":"09", "name": "Nitin", "department":"Finance"}'print("This is JSON",type(emp))print("\nNow convert from JSON to Python")# Convert string to Python dictd=json.loads(emp)print("Converted to Python",type(d))print(d)

Output
This is JSON <class 'str'>Now convert from JSON to PythonConverted 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
importjson# JSON stringd={'id':'09','name':'Nitin','department':'Finance'}print("This is Python",type(d))print("\nNow Convert from Python to JSON")# Convert Python dict to JSONobj=json.dumps(d,indent=4)print("Converted to JSON",type(obj))print(obj)

Output
This is Python <class 'dict'>Now Convert from Python to JSONConverted 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

Reading and Writing JSON

Parsing JSON

Serializing and Deserializing JSON

Conversion between JSON

More operations JSON


Improve
Article Tags :
Practice Tags :

Similar Reads

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 ourCookie 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

[8]ページ先頭

©2009-2025 Movatter.jp