rest - Parse json and choose items\keys upon condition -


i'm trying parse json file rest api. json has few arrays, , i'd choose specific item array based on value of item.

for example:

[   {     "item1": true,     "item2": "value"   },   {     "item1": false,     "item2": "value"   } ] 

i'd check if item1 true, , then, want value item2.

how handle it? i've tried use json parser named underscore great, cant final result.

thanks

first need parse:

var objjson = json.parse(yourjsontext); 

and check condition

if( objjson[0].item1 === "true"){  } 

for shell scripting using jq, copy json test.json:

jq '.[0].item1' test.json 

you try on jqplay

enter json , enter ".[0].item1" filter


Comments