How to replace JSON value

Mohan22
Tera Expert

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

2 REPLIES 2

Allen Andreas
Administrator
Administrator

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

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