Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Find value using key in JSON

Viswasri Ponaka
Tera Contributor

Hi Team,

I have an system property as below and I already have a key as 'support_group_1', Now I need to fetch only the specific value from the key (I need 'low' from 'name1',"name2','name3' in the below JSON)

​{    "support_group_1": [        {            "name1":            {                "low": "95",

                "over" : "200"            }        },        {            "name2":            {                "low": "85",                "over":"100"            }        }    ],

"support_group_2":[

{

  "name3":{

        "low":100

      }

}

]

}

1 ACCEPTED SOLUTION

suvro
Mega Sage

var value = [];

var parsedValue = JSON.parse(gs.getSystemProperty('name_of_system_property'));

for ( var key  in  parsedValue) {

 for (var j =0; j < parsedValue[key].length; j++){

     for ( var key2 in parsedValue[key]){

       value[key2] = parseValue[key].[key2].low;

}

}

}

 

View solution in original post

3 REPLIES 3

suvro
Mega Sage

var value = [];

var parsedValue = JSON.parse(gs.getSystemProperty('name_of_system_property'));

for ( var key  in  parsedValue) {

 for (var j =0; j < parsedValue[key].length; j++){

     for ( var key2 in parsedValue[key]){

       value[key2] = parseValue[key].[key2].low;

}

}

}

 

Maik Skoddow
Tera Patron
Tera Patron

Hi

You can use the following page to find out the right path: https://jsonpathfinder.com/

Maik

Thanks for this. it helps a lot 🙂