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?
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:-