Home > OS >  JSON formatting in Apex
JSON formatting in Apex

Time:03-09

I am getting a JSON in below format:

{
"A":"1",
"B":"2"
}

I have a field update and JSON at some point could be too long. How can I change the JSON format to below pattern?

{"A":"1","B":"2"}

I am trying to store this minified JSON format on a field, so that char limit issue is resolved.

CodePudding user response:

deserialize the string and serialize it again and then update the field. Declare the JSON as string

Map<String,Object> parser = (Map<String,Object>)JSON.deserializeUntyped(yourstring);
yourstring = JSON.serialize(parser);

You can change Map accordingly. Required format will be present in string variable.

  • Related