Reputation: 25
I am trying to get a particular value from nested JSON
JSON is as below
{
"ListOn": true,
"currentList": "Counter_Master",
"deployedList": [
{
"name": "Master",
"skipForSchedule": false,
"Type": "regular"
},
{
"plType": "regular",
"skipForSchedule": false,
"name": "Name_test"
}
],
"uptime": 1216.819
}
This is what I did till now
import json
with open('config.json') as f:
#print("file is open")
data = json.load(f)
curr_list = data['deployedPlaylists'] [1] . values()
curr_list = curr_playlist[1]
print("we are finding the name of curr_list[1]", curr_list)
I am not able to pickup 2nd name which is "Name_test" in deployedList[1].name
from shell, I can do with below command, want to do in python, but as I am new to python could not find the exact way.
sudo jq -r '.deployedlists[1].name' _config.json
Requesting for help. Thanks
Upvotes: 0
Views: 58
Reputation: 66
I think you just have typos in your code
Just fix data['deployedPlaylists'] [1] . values()
to be data['deployedList'] [1]['name']
which will be storing the value Name_test
as required.
just take in mind that json.read()
returns the value of the json file in python dictionary so to manipulate the values of the json file read more about python dictionaries how they are stored and how to access their values.
Upvotes: 1