How to get some selected values to get printed from json object?

sabbani rishika
Tera Contributor

script needed

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you should be able to parse using JSON parser and get the values

Since you said it's confidential one we can just provide example from our side and rest part you need to take care of.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Mahendra RC
Mega Sage

Hello Sabbani,

Please share your JSON Object data so that it is easy to understand. but suppose below is your Json Object

var fieldData = {"type":"string","label":"Assignment Group","value":"System Administrator","readonly":true,"mandatory":true};

then you can print as shown below:

for (var keys in fieldData) {

gs.print(keys + " : " + fieldData[keys]); 

}

Output: (when executed in background script)

*** Script: type : string
*** Script: label : Assignment Group
*** Script: value : System Administrator
*** Script: readonly : true
*** Script: mandatory : true

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

Its not working sir...

Actually my json object is confidential one, so couldn't share.If i use your code the output which i'm getting i'll share here.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you should be able to parse using JSON parser and get the values

Since you said it's confidential one we can just provide example from our side and rest part you need to take care of.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Its already in json object format, then why again should we use json.parse()?

could you share the code for getting specified values to get printed from json object?