A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/json-loads-in-python/ below:

json.loads() in Python - GeeksforGeeks

json.loads() in Python

Last Updated : 09 May, 2025

JSON is a lightweight data format used for storing and exchanging data across systems. Python provides a built-in module called json to work with JSON data easily. The json.loads() method of JSON module is used to parse a valid JSON string and convert it into a Python dictionary. For example:

Python
import json

s = '{"language": "Python", "version": 3.11}'

p = json.loads(s)

print(p)

Output
{'language': 'Python', 'version': 3.11}

Explanation:

In this article, we'll learn about the json.loads() method, how it works and practical examples to parse JSON strings into Python objects:

Syntax

json.loads(s)

Parameters:

Return Type: An Python object (typically a dict, but can also be a list, int, float, str, etc., based on the JSON structure)

Examples of json.loads() method Example 1: Basic JSON Parsing

Let’s assume, we have a JSON string containing personal information. The below code demonstrates how to convert it to a Python dictionary.

Python
import json

x = """{
    "Name": "Prajjwal Vish",
    "Contact Number": 1111111111,
    "Email": "prajjwal@gmail.com",
    "Hobbies": ["Reading", "Sketching", "Playing Chess"]
}"""

y = json.loads(x)

print(y)

Output
{'Name': 'Prajjwal Vish', 'Contact Number': 1111111111, 'Email': 'prajjwal@gmail.com', 'Hobbies': ['Reading', 'Sketching', 'Playing Chess']}

Explanation:

Example 2: Iterating Over Parsed Data

Once parsed, we can loop through the dictionary just like any other Python dict:

Python
import json

e = '{"id": "09", "name": "Nitin", "department": "Finance"}'

e_dict = json.loads(e)

for key in e_dict:
    print(key, ":", e_dict[key])

Output
id : 09
name : Nitin
department : Finance

Explanation:

Related Article:



RetroSearch 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