Activity Forums Salesforce® Discussions Which parsing method is better - Deserialisation or JSON Parser? And Why?

  • madhulika shah

    July 12, 2018 at 1:07 pm

    JSON is the most preferred way of transferring data over web. We use this most in salesforce when integrating with an external system. In most of the integrations, you typically use HTTP Callouts to the end points defined by various services, and the most common response format returned by these is JSON. Parsing this JSON would be very time consuming . One way of doing this would be manually parsing the complete JSON using the JSONParser method but Deserialization parsing method is better because

    <Class/Object> n = (<Class/Object>)JSON.deserialize('JSON', <Class/Object>.class);

    This one statement would completely deserialize the JSON and store the values in the respective member variables of the class.

  • Avnish Yadav

    July 12, 2018 at 1:17 pm

    Hello Shradha,

    I would say JSON Deserialization is better because it's an automatic parser while in JSON Parser method, you need to parse JSON manually.


  • shariq

    September 19, 2018 at 2:11 am


    I would Use JSON Deserialization.

    jsonStr = '{//some JSON data}'
    JSONParser parser = JSON.createParser(jsonStr);
    String text = '';
    while (parser.nextToken() != null) {
    if(parser.getCurrentToken() == JSONToken.START_OBJECT){
    text = parser.getText() + ', ' + text;
    //System.debug(parser.getText() + parser.nextToken() + ' - ' + parser.getText());
    if (parser.getCurrentToken() == JSONToken.START_ARRAY) {
    text = parser.getText() + ', ' + text;

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos