How to save data in JSON format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 11:49 PM
Hi All,
I am quering a table and want to save this record , so my format looks like this .
so first one is the Sys_id and it has more than 1 record associated with it. which i am getting from a table. how can have a Json for this and then how can i fetch values from this.
{ "1233898823190" : ["123", "234", "476879"]}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 12:15 AM
Hi Priya,
You can use below logic to prepare your JSON.
var incGR = new GlideRecord('incident');
incGR.setLimit('5');
incGR.query();
var obj3 = {};
while(incGR.next()){
var obj2 = {};
obj2.number = incGR.number.toString();
obj2.description = incGR.description.toString();
var sys = incGR.sys_id;
obj3[sys] = obj2;
}
gs.print('obj2 '+JSON.stringify(obj3));
Please mark correct if helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 12:21 AM
Hi Priya,
Here's one detailed article which explains how to store and fetch data in JSON: Store & Fetch Value from JSON
Hope this helps you.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 12:58 AM
Hi,
You can use below format
{
"sysid1" : "123, 234, 4567",
"sysid2" : "345, 678"
}
//similarly for others
And to fetch the values
var prop = gs.getProperty("property_name").toString();
var sysid1 = prop.sysid1;
var first_array = sysid1.split(',');
first_array[0]; //to get 123
first_array[1]; //to get 234
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2022 05:06 AM
Feel free to reach out if you have further questions or else you can mark an answer as correct and helpful to close the thread so that it benefits future visitors also.
Regards,
Sumanth