2

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

3
  • 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 Commented Jul 18, 2016 at 9:00
  • String is not an json object :)) Commented Jul 18, 2016 at 9:12
  • Rajarshi Das... ahh didn't noticed how you generated string
    – Ratan Paul
    Commented Jul 18, 2016 at 9:13

1 Answer 1

5

You can use JSON.serialize() method.

For reference check here

2
  • ahh that what I am looking for Commented Jul 18, 2016 at 9:12
  • sure no question on it Commented 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 .