×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Convert from JSON to Python object

By IncludeHelp Last updated : February 20, 2024

To convert a JSON to a Python object, you can use the json.loads() method by passing a JSON string. The json.loads() method parses a valid JSON string and converts it into a Python object (dictionary).

Python program to convert JSON to an object

This example demonstrates converting from JSON to Python object.

# Import the json module
import json

# Creating a JSON string
student = '{"id":"101", "std_name": "Alex", "course":"MCA"}'
# Printing value and types of 'student'
print("student :", student)
print("Type of student :", type(student))

# Converting JSON string to Python object
result = json.loads(student)

print("After converting...")
print("result :", result)
print("Type of result :", type(result))

Output

The output of the above program is:

student : {"id":"101", "std_name": "Alex", "course":"MCA"}
Type of student : <class 'str'>
After converting...
result : {'id': '101', 'std_name': 'Alex', 'course': 'MCA'}
Type of result : <class 'dict'>

To understand the above program, you should have the basic knowledge of the following Python topics:

 
 
Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.