Working with JSON

JavaScript Object Notation (JSON). When integrating Salesforce with external services, the most common protocol is REST API and we will be commonly using JSON format to send and receive data between Salesforce and the external system.

Parsing JSON means interpreting the data with whatever language u are using at the moment. When we parse JSON, it means we are converting the string into a JSON object by following the specification, where we can subsequently use in whatever way we want. Here is an example:

// Received json body data:
jsonBody = '[{"pnm__c":"pname1", "material__c":"materialname1"}, {"pnm__c":"pname2", "material__c":"materialname2"}]';

// Records received from json into a list of Data__c object
List dList = (List) System.JSON.deserialize(jsonBody, List.class);
System.debug('dList : ' + dList);