- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 08:38 PM
Hello,
I am trying to figure out a way to add values to below Json object
Eg Json object -
{
"kind":"tm:ltm:data-group:internal:internalstate",
"name":"smtp_whitelist",
"fullPath":"smtp_whitelist",
"generation":1,
"selfLink":"https://localhost/mgmt/tm/ltm/data-group/internal/smtp_whitelist?ver=13.1.1.4",
"type":"ip",
"records":[
{
"name":"10.1.1.1/32",
"data":""
},
{
"name":"192.168.1.1/32",
"data":""
},
{
"name":"192.168.1.2/32",
"data":""
},
{
"name":"192.168.2.0/24",
"data":""
}
]
}
trying to figure out a way to add new set of values like below under "records":[
{
"name":"test",
"data":"test"
}
I am able to iterate using below code but unable to add
gs.print("code: " + httpResponseStatus);
gs.print("body: " + JSON.parse(response.getBody()));
var b = JSON.parse(response.getBody())
var data = b.records;
for (var i in data)
{
var id = data[i].name;
var name = data[i].data;
gs.print("body 1: " + id);
gs.print("body 1: " + name);
}
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 09:13 PM
Hello,
You can add another set of values by pushing another object into that "records" array, i.e.
gs.print("code: " + httpResponseStatus);
gs.print("body: " + JSON.parse(response.getBody()));
var b = JSON.parse(response.getBody())
var data = b.records;
//Just an example, you could also push the details directly to b.records variable
//and can then convert b variable back to JSON string if that's what you wanted to do
data.push({"name" : "test", "data" : "test"});
for (var i in data)
{
var id = data[i].name;
var name = data[i].data;
gs.print("body 1: " + id);
gs.print("body 1: " + name);
}
That would add another set of values / JSON object in the records array.
Hope this helps!
Cheers,
Manish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 09:13 PM
Hello,
You can add another set of values by pushing another object into that "records" array, i.e.
gs.print("code: " + httpResponseStatus);
gs.print("body: " + JSON.parse(response.getBody()));
var b = JSON.parse(response.getBody())
var data = b.records;
//Just an example, you could also push the details directly to b.records variable
//and can then convert b variable back to JSON string if that's what you wanted to do
data.push({"name" : "test", "data" : "test"});
for (var i in data)
{
var id = data[i].name;
var name = data[i].data;
gs.print("body 1: " + id);
gs.print("body 1: " + name);
}
That would add another set of values / JSON object in the records array.
Hope this helps!
Cheers,
Manish