I am new to json. I have json output that looks like this
[
{
"employees": {
"education": "BE\/B.Tech"
},
"0": {
"count": "1"
}
},
{
"employees": {
"education": "MBA"
},
"0": {
"count": "3"
}
}
]
I want to retrieve the employee’s education and the count. I have tried but i am not able to retrieve the values.
I appreciate any help.
Thanks.
Assuming your JSON string is in a variable
$json, it goes like this:Then you can access the information via:
You can also loop over the array and access all the different
educationthis way.Update:
To better demonstrate which expression accesses which information:
Generally
employees_list[0].employeesis the same asemployees_list[0]["employees"]but this does not work for numbers, because properties and variables are not allowed to start with numbers. So you can only useemployees_list[0].["0"]and notemployees_list[0].0.The structure of your JSON string looks a bit strange though. You should consider to structure it differently if you can.
For example:
The
"0"key in your original JSON string seems to serve no purpose and just complicates the access.