[SalesForce] Apex convert String to JSON

I want to response as a json not string

String jsonString =  '{"method": "POST","url": "types","body": {"name": "Ranjit121212","description":"ranjit34443333"}'; 
String accountsJSON = JSON.createGenerator(jsonString)
System.debug(accountsJSON);

the above create a string response like

3]|DEBUG|"{\"method\": \"POST\",\"relative_url\": \"types\",\"body\": {\"name\": \"Ranjit121212\",\"description\":\"ranjit34443333\"}"

But I want to response it as a JSON

Please help.

I am new in Apex. So Please forgive if it is a basic question

Best Answer

You can use JSON.serialize() method.

For reference check here

Related Topic