I'm facing some issues with JSON deserializing. I have a JSON format data from my existing webservice and I have collected all that data and made a .txt file and uploaded as a static resource. So my question is, how can I utilize that static resource file in apex class ? Here is my JSON format Data :

array(10) {
  array(19) {
    string(8) "13095524"
    string(10) "5000115236"
    string(17) "SAJBB4AG0HCY38725"
    string(5) "20067"
    string(14) "Aditya Suzuki"
    string(6) "SUzuki"
    string(10) "Baleno"
    string(8) "TDI"
    string(8) "2.0 GTDi"
    string(3) "1AA"
    string(13) "Polaris White"
    string(3) "RNR"
    string(5) "Latte"
    string(4) "2017"
    string(9) "18-Jul-16"
    string(12) "Dealer Stock"
    string(6) "closed"
    string(0) ""
    string(1) "Y"

There are many more records like this. So, how can I parse this and get it to deserialize in a list or arrays?

I have tried to create a class for this as well. I'll show what I have done until now :

public class JSON2Apex {
    public static void consumeObject(JSONParser parser) {
        Integer depth = 0;
        do {
            JSONToken curr = parser.getCurrentToken();
            if (curr == JSONToken.START_OBJECT || 
                curr == JSONToken.START_ARRAY) {
            } else if (curr == JSONToken.END_OBJECT ||
                curr == JSONToken.END_ARRAY) {
        } while (depth > 0 && parser.nextToken() != null);

    public class JsonDeserialize {
        public String cso_no {get;set;} 
        public String product_id {get;set;} 
        public String vin_no {get;set;} 
        public String dlrid {get;set;} 
        public String current_allocation_dlr {get;set;} 
        public String brand {get;set;}  
        public String model {get;set;} 
        public String submodel {get;set;} 
        public String engine {get;set;} 
        public String ext_colour_code {get;set;} 
        public String ext_colour {get;set;} 
        public String int_colour_code {get;set;} 
        public String int_colour {get;set;} 
        public String model_yr {get;set;} 
        public String mfg_yr {get;set;} 
        public String order_status {get;set;} 
        public String stock_status {get;set;} 
        public String specification {get;set;} 
        public String show_udaan {get;set;} 

        public JsonDeserialize(JSONParser parser) {
            while (parser.nextToken() != JSONToken.END_OBJECT) {
                if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {
                    String text = parser.getText();
                    if (parser.nextToken() != JSONToken.VALUE_NULL) {
                        if (text == 'cso_no') {
                            cso_no = parser.getText();
                        } else if (text == 'product_id') {
                            product_id = parser.getText();
                        } else if (text == 'vin_no') {
                            vin_no = parser.getText();
                        } else if (text == 'dlrid') {
                            dlrid = parser.getText();
                        } else if (text == 'current_allocation_dlr') {
                            current_allocation_dlr = parser.getText();
                        } else if (text == 'brand') {
                            brand = parser.getText();
                        } else if (text == 'model') {
                            model = parser.getText();
                        } else if (text == 'submodel') {
                            submodel = parser.getText();
                        } else if (text == 'engine') {
                            engine = parser.getText();
                        } else if (text == 'ext_colour_code') {
                            ext_colour_code = parser.getText();
                        } else if (text == 'ext_colour') {
                            ext_colour = parser.getText();
                        } else if (text == 'int_colour_code') {
                            int_colour_code = parser.getText();
                        } else if (text == 'int_colour') {
                            int_colour = parser.getText();
                        } else if (text == 'model_yr') {
                            model_yr = parser.getText();
                        } else if (text == 'mfg_yr') {
                            mfg_yr = parser.getText();
                        } else if (text == 'order_status') {
                            order_status = parser.getText();
                        } else if (text == 'stock_status') {
                            stock_status = parser.getText();
                        } else if (text == 'specification') {
                            specification = parser.getText();
                        } else if (text == 'show_udaan') {
                            show_udaan = parser.getText();

    public static JSON2Apex parse(String json) {
        return (JSON2Apex)System.JSON.deserialize(json, JSON2Apex.class);

I'm new into this JSON parsing so dont know much about it. Can someone guide me through it.

Thanks in advance to all.

  • You can refer this answer Nov 11, 2017 at 6:59
  • Does not look like json to my. Looks more like the output of a Javascript object???
    – Eric
    Nov 11, 2017 at 7:31
  • Well, it is an array of data but i have similar to it in the json format. So any more suggestions on it ?
    – Hardik B
    Nov 11, 2017 at 9:48

1 Answer 1


Do ensure that your static resource is in JSON format; you can check that using a JSON validator e.g. https://jsonformatter.curiousconcept.com/.

The JSON.deserialize(jsonString, apexType) method is the first thing to try as it does all the deserializing work for you. That work is controlled by the second argument, and the simplest way to generate that class is to give JSON2Apex an example of your JSON and let it work out the corresponding class definitions.

So the deserialization becomes this simple:

public static JSON2Apex parse(String json) {
    return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);

(JSONParser requires you to do a lot of coding that embodies the expected structure - very error prone and hardly ever necessary to do.)

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.