'JSON formatting in Apex

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source