Parsing rest api data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 01:38 PM
I am getting back data from external system from rest api, I am trying to parse it but could not get it to work.
{
"meta": {
"totalItems": 736,
"pagingOffset": "0",
"pagingLimit": "1000"
},
"allPerson": [
{
"Id": 332,
"RCId": "000001",
"Type": 1,
},
{
"Id": 333,
"RCId": "000003",
"Type": 3,
},
]
I tried to parse using:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 01:16 AM
@samadam Please update your code as follows and see if it works for you.
var responseBody = response.getBody();
var response1= JSON.parse(responseBody);
for(i=0;i<2;i++) {
// process json object
gs.info(response1.allPerson[i].Id);
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 11:02 AM
That worked.
If I have a lot of fields is there a way to access all the field names and then set those values without manually specifying each field?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 11:24 AM
@samadam Glad to know it worked for you. Please mark the response an accepted solution and helpful.
Regarding your question related to field names, you need to set each one of them there are ways to extract the key value pairs from an object. However, they still need to be associated with the field names on form which needs to be done manually.