Skip to main content

Hi

 

I use the JSON Object Manager regularly for retrieving or setting values from a JSON string.

But how can I actually add elements to an array?

For example, I have a JSON string like {"employer":"Joe","roles"::]} and I would like to add roles so the result should look like {"employer":"Joe","roles"::{"roleID":"developer"},{"roleID":"analyst"}]}

 

Any ideas how to do that with JSON Object Manager Package?

Hi @MICAH SMITH​ 

Since you recorded a quickstep using the JSON Object Manager, I was hoping that you could shine your light on my question?

Is would like to know if it is actually possible to create or extend a JSON object using the JSON Object Manager?

Thanks in advance,

 

Nordine


I dont think you can do it in the JSON Object Manager package...I believe you can only set values there, not actually adding elements...I think the easiest way to do it in Automation 360 would be to have a small JavaScript function that could do it.

 

var jsonStr = '{"employer":"Joe","roles"::]}';

var obj = JSON.parse(jsonStr)

objj'roles'].push({"role":"developer"});

jsonStr = JSON.stringify(obj); 

console.log(jsonStr);

 

you'd just need to make that a function and pass in your JSON as a string in a list as well as the target object add as a string of the same list.

 


Thanks for your reply. I think that your suggestion to use JavaScript is at least a more elegant solution than doing string manipulations.


Reply