function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vivek_PatelVivek_Patel 

Updating the existing JSON

Hi,

I am trying to update a exiting JSON structure, but I couldn't find any method or way to do that.

This is how I am creating the JSON
 
JSONGenerator generator = JSON.createGenerator(true);
generator.writeStartObject();               
generator.writeStringField('action', 'VerifyEmail');
generator.writeEndObject();      
System.debug(generator.getAsString());

and now I want to update the existing "action" field's value and write some new fields in the same JSON.

Does apex support this?
Best Answer chosen by Vivek_Patel
Shrikant BagalShrikant Bagal
Hi Vivek_Patel,

Please deserialize your JSON in Map and then add new Field using put method of Map.
and again serialize it.

Thanks!