Array of JSON objects
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 11:17 PM
Hi,
How to initialize, add, remove objects to JSON array.
Scenario is below,
I've a scheduled job which will call a script include function which would return list of sys-id and field value of the record.
Thanks.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 12:29 AM
Hello balaji
Check this script:
var books = [];
var bookTitle = "Tom Sawyer";
var author = "Mark Twain";
var foo = {};
foo[bookTitle] = author;
books.push(foo);
gs.log(JSON.stringify(books));
OUTPUT:
*** Script: [{"Tom Sawyer":"Mark Twain"}]
Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 12:20 AM
Hi Balaji,
var arr = {};
var arrMain = [];
arr.test1 = "ABC";
arr.test2 = "DEF";
arrMain.push(JSON.stringify(arr));
gs.print(arrMain);
Try this in your background script its result will be-
*** Script: {"test1":"ABC","test2":"DEF"}
Hope this helps too.
Regards,
Omkar Mone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 12:44 AM
Hi G Balaji,
As you are trying to create and use JSON Objects in your server side scripting, you may look into the below helpful links. These links contains the required examples to understand how to create and use the JSON arrays.
1. Advanced Scripting and JSON
2. JSON
Hope this helps. Please mark the answer Correct/Helpful based on the impact.
Regards,
Amlan