How to print particular JSON value in Python

Hi, everyone in this post we will learn How to print particular JSON values in Python.

what is the JSON file?

JSON stands for JavaScript Object Notation and it is used to store data in an organized manner.

To import JSON files in Python we use:-

data=json.load(“Name of the file”)

So after importing the data, the question arises that how we can access the data inside the JSON file.

So we only have to use the slicing method which we often use in strings or lists.

Now take a look at the code to access a particular data in the JSON file.

import json

fp=open("example_2.json")
data=json.load(fp)
print("Here is the data whic we have imported\n",data)
#  Use the slicing to get a particular value from a json file.
print("First Print")
print(data['quiz']['sport'])
print("Second Print")
print(data['quiz']['sport']['q1']['options'])

Here is the output:-

Print particular JSON value in Python

Thank You

Also read: Python program to extract a single value from JSON response (Using API call)

Python JSON Encoder and Decoder

Leave a Reply

Your email address will not be published. Required fields are marked *