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)

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

  • no but I want to should responsean apex json object so that when I call it in postman it should not give string it should return json Jul 18, 2016 at 9:00
  • String is not an json object :)) Jul 18, 2016 at 9:12
  • Rajarshi Das... ahh didn't noticed how you generated string
    – Ratan Paul
    Jul 18, 2016 at 9:13

1 Answer 1


You can use JSON.serialize() method.

For reference check here

  • ahh that what I am looking for Jul 18, 2016 at 9:12
  • sure no question on it Jul 18, 2016 at 9:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .