How To Parse JSON In Python?

JSON is a popular data format that is also supported by the Python programming language. The Python programming language provides the json module in order to work with JSON data. The loads() method of the json module can be used to parse JSON data. Another way the json.load() can be used is to parse JSON data.

json.load() Method Syntax

Python provides the json.load() method in order to parse JSON data. The syntax of the json.load() method is like below.

json.load(JSON_DATA)
  • JSON_DATA is the JSON formatted data.

Parse JSON Data

It is very easy to parse JSON data in Python. We will just provide the JSON data or text into the json.load() method as parameter.

import json

data = '{"name":"ismail","surname":"baydan","age":30}'

parsed_json = json.load(data)

The JSON data is presented as a string but the very same structure as the Python dictionary type. The parsed data is stored inside nested lists.

Iterate over Parsed JSON Data

As JSON data is parsed into list structure in Python e can easily iterate over this JSON data by iterating over the list.

import json

data = '{"name":"ismail","surname":"baydan","age":30}'

parsed_json = json.load(data)

for i in parsed_json:
   print(i)

Leave a Comment