I am doing this:


where payload is an object instance.

and getting this:

"{\"signup\":{\"salesforce_id\":\"003110022068XNz\",\"nationbuilder_id\":65536,\"last_name\":\"Downs\",\"first_name\":\"Danny\",\"email1\":\"persoxxxn@example.com\",\"do_not_call\":false,\"address\":{\"zip\":\"E12 6FF\",\"state\":null,\"fips\":null,\"county\":null,\"country_code\":null,\"country\":\"Great Britain\",\"city\":\"Norwich\",\"address3\":null,\"address2\":null,\"address1\":\"123 Fake St\"}},\"responseMessage\":\"OK - CONTACT UPDATED\"}"

I'd really rather not have to parse and remove all of the escape '\' backslashes. I am sure I have serialised JSON before without this issue?

I did try a straightforward replace('\',''); but this didnt have an effect.

| improve this question | | | | |

Here is a solution to a similar problem:

To return a string without the quotes, set it as the response body:

RestContext.response.addHeader('Content-Type', 'application/json');
RestContext.response.responseBody = Blob.valueOf(JSON.serialize(payload));
| improve this answer | | | | |
  • Thanks, can I get that out as a string though? – dacology Jan 15 '14 at 11:47
  • Thank... yes this works. My approach was wrong, my @HttpPost method was returning a string, which I was building. But with your approach is correct. I now return void, but set the responseBody as you describe. – dacology Jan 15 '14 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.