Add NEW key and value to JOBJECT

Hi Newbie here,

How to add new pair of key and value to JOBJECT?
for example I have a JOBJECT

jobjectVar =
{
“Name”: “Nayeon”,
“Age”: 24
}

I would like to add new key and value the output must be like this.
jobjectVar =
{
“Name”: “Nayeon”,
“Age”: 24,
“Idol”: True
}

Hi @Ryan_Christian_Buan

Use deserialize json activity and check it

Thanks
ASHWIN.S

1 Like

Hi @ashwinsrini88

Yes initially, I will read a text file that gives me string and then deserialize to jobject. I already did that part what would I want next is to after deserialize, I want to add new set of key and value to that object.

Thanks.

Hi @Ryan_Christian_Buan

Yes ensure you use for each item

Thanks
ASHWIN.S

@ashwinsrini88
How would a for each item can add new pair of key and value?

Hi @Ryan_Christian_Buan

By using item .key and item.value with add to dictionary

Thanks
Ashwin.S

HI @Ryan_Christian_Buan

Check below post

Hope this helps

Thanks

Hi @Srini84,

Upon checking on the post. It only shows how to update value of a key not add new set. Though it shows an idea of updating the content by using string.replace, I would like to avoid string actions when updating /adding values to my objects .

But still thanks for sharing :slight_smile:

Hi, you probably moved on from this issue but incase it helps anyone else.
I used an invoke code acitivity and passed the jobject as an in/out argument.

The code I used to add a property to the end of the JObject was:

TestJobject.Add(new JProperty(“NewProperty”,“New Value”))

I adapted an example from this website if you want more info:
[https://www.newtonsoft.com/json/help/html/ModifyJson.htm](http://)

6 Likes