How to replace JSON value
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2022 06:41 AM
Hi Team,
I have below JSON and i want to replace id value with sysid. please suggest on this.
current payload:
[
{
"name":"abcd",
"location":"efgh",
"id":"ijkl"
}
]
required payload:
[
{
"name":"abcd",
"location":"efgh",
"id":"1234567890"
}
]
Thanks in advance.
Gan
Labels:
- Labels:
-
Incident Management
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2022 07:25 AM
Hi,
Thanks for posting your requirement.
- What have you tried thus far?
- What has worked/hasn't work?
- What troubleshooting, etc. have you done?
Please mark reply as Helpful, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2022 07:29 AM
Hi Gan,
Here's some example code to help you out:
var jsonObj ={
"name":"abcd",
"location":"efgh",
"id":"ijkl"
}
gs.info("Old value = " + jsonObj.id);
var sysId = "sysIdGoesHere";
jsonObj.id = sysId; //this is where to set it
gs.info("New value = "+jsonObj.id);
This code returns the below, where you can see the change taking place:
*** Script: Old value = ijkl
*** Script: New value = sysIdGoesHere
Cheers
Mike