how can i read Json data for specific parameters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2023 07:44 AM
Hi Team,
Below is the JSON data updated in 1of the variables in catalog item.
{
"id":"123",
"region":"us-east-1",
"name":"123@gmail.com"
} i above JSON i need to read id & name details. how can i develop script for the same.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2023 09:11 AM
@Emp 53 Could you please let me know what type of variable is bulk_info? Please share a snapshot of this variable if possible.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2023 09:44 AM
@Emp 53 If it is a multiline text then the JSON parsing might be breaking due to the carriage return /r or new line characters /n. Please check if the following code fixes your issue.
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', 'RITM1100611');
gr.query();
var jsonVar='';
while(gr.next()) {
jsonVar = JSON.parse(gr.variables.bulk_info.replace(/\r?\n|\r/g, "")); //replace variable name with variable containing JSON data
gs.print('id: '+jsonVar.id);//will print id
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2023 09:54 AM
still facing same issue. can you suggest which variable i need to use if multiline text not work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2023 10:25 AM
@Emp 53 if you are taking a JSON input in the multiline text field than the chances of variable having /r/n characters are higher. You would need to remove all the new line characters from the variable and finally your variable should have the text
{ "id":"123", "region":"us-east-1", "name":"123@gmail.com" }
without any newlines. Then only JSON.parse will be able to work.