Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
Please guide me with Json As i am new to SF -> Json 

I am executing this in Developer Console. 

string leads ='[{"FirstName":"Kishore","LastName":"B T","Company":"IPL","City":"Bangalore",'+

 '   "State":"KA","PostalCode":560068,"Phone":8105690988,"Status":"Open - Not Contacted",'+

     '   "Tags":[]},{"FirstName":"deeps","LastName":"O M","Company":"vv",  '+

        '    "City":"Bangalore","State":"KA","PostalCode":560078,"Phone":95055556343,'+

            '    "Status":"Open - Not Contacted","Tags":[]} ]';

String leadsJSON = JSON.serializePretty(leads);

system.debug('accountsDeserialized ++ '+leadsJSON);

List<lead> accountsDeserialized = (List<lead> ) JSON.deserialize(leadsJSON, List<lead>.class);

system.debug('accountsDeserialized ++ '+accountsDeserialized);

I have validated this json in http://json2apex.herokuapp.com/but i get this error

**System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set**

Let me know Where I am going wrong.
5 answers
  1. Nov 25, 2015, 11:22 AM
    Hi SRK,

    My question is how deserialize the string if there are multiple records,

    I can serialize the records by querying as you have suggested but how to deserialize the same?
Loading
0/9000