I'm trying to deserialize http json output . Getting an ERROR :System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set

 public static void syncBC(){
        HttpResponse respond = getrespond();


                list<customerLedgerEntry> clist= new customerLedgerEntry().parse(respond.getbody());

    public static HttpResponse getrespond(){
        Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint ('callout:Bc_test/PBCLE');
        HttpResponse response = Http.send(request);
        return response;

    public class customerLedgerEntry{
        public String Entry_No;
        public Date Posting_Date;
        public String Document_Type;
        public String Document_No;
        public String Customer_No;
        public Decimal Amount_LCY;
        public Decimal Amount;
        public Date Initial_Entry_Due_Date;

        public list<customerLedgerEntry> parse(String json){

            return(list<customerLedgerEntry>) System.JSON.deserialize(json, list<customerLedgerEntry>.class);



Here is the JSON output example:

            "Entry_No":1,"Posting_Date":"2018-11-05","Entry_Type":"Initial Entry","Document_Type":"xxx",

            "Entry_Type":"Initial Entry","Document_Type":"xxx",
  • Something that I've noticed - looking at the JSON it seems like it is malformed. The value for Cust_Ledger_Entry_No is xxx instead of an actual string like so "xxx". You can try validating the JSON here - jsonlint.com. – Arthlete Jun 9 at 5:39

First, you have to deserialized untyped as your JSON is not a list of customerLedgerEntry. Then you can deserialize typed.

I have removed some of the invalid values from your JSON, and its working fine now. For Demo, I have just kept one record. See this is how it works.

Map<String, Object> jsonMap =   (Map<String, Object>) JSON.deserializeUntyped('{ "@odata.context":"https://api.businesscentral.dynamics.com/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "value":[ { "Posting_Date":"2018-11-21", "Entry_Type":"Initial Entry", "Document_Type":"xxx", "Document_No":"1234", "Customer_No":"5423"} ] }');

list<object> entrylisttemp = (list<object>)jsonMap.get('value');
list<testDeserialize.customerLedgerEntry> entries = (list<testDeserialize.customerLedgerEntry>)System.JSON.deserialize(JSON.serialize(entrylisttemp), list<testDeserialize.customerLedgerEntry>.class);
| improve this answer | |
  • Thankyou Rahul. Now I'm getting System.LimitException: Apex heap size too large: 22645046, I think i need to write a batch class for not hitting the heap size. – jagadeesh parasa Jun 9 at 5:48
  • what is the size of entry list ? is it so big? @jagadeeshparasa – rahul gawale Jun 9 at 6:02
  • Yes @Rahul the size of entry list is like 23MB – jagadeesh parasa Jun 9 at 6:07
  • @jagadeeshparasa then you need to fetch that in smaller chunks, and yes batch will be fine. Just make sure that you request data in smaller chunks – rahul gawale Jun 9 at 6:16
  • can you send me the sample code to fetch the data in smaller chunks @Rahul – jagadeesh parasa Jun 9 at 8:38

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.