I am getting a json response from an API call.

System.debug('result is : ' + responseToken.getBody())

//This response.body format is as below:



I want to convert this to a map so that I can get the following format:

new Map<String, Object>{
                        'Email' => ,
                        'firstName' => ,
                        'lastName' =>    

Please suggest!


With this specific JSON, you can also deserialize straight into a Map:

Map<String, String> values = (Map<String, String>)
    JSON.deserialize(responseToken.getBody(), Map<String, String>.class);

From there, you can easily get the values back out:

String email = values.get('email');

JSON class has deserializeUntyped method that converts JSON to map.

Sample code:

String jsonInput = '{"email":"are02@gmail.com","LastName":"ABCD","FirstName":"ACFPY","Suffix":"","Title":"Engineer","Psw":"","PhoneCode":"","Phone":"100-000-000"}';

Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(jsonInput);

You can read more about JSON parsing here. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm

  • How to get values from this map ? – Ruchi Feb 28 '18 at 13:12
  • please avoid follow up questions in comments, take some time to read How to Ask and take the tour. When opening posts on the forum, make sure you at least incldue what you have tried rather than posting requriements or how to questions. thanks – glls Feb 28 '18 at 14:37

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.