Saturday, 2 April 2022

JSON parsing with Map Sample for getting list of values

 Hi,

Here we are going to learn how to get the values from an array that has plain values instead of a list of JSON objects.

Let's take the example below.

Here we have "langaugeskills" array in the following JSON String with the values "English,Hindi, Telugu". To capture those values we have to follow the below approach.


String jsonStr = '{"LastName": "Balu","langaugeskills": ["English","Hindi","Telugu"]}';

Map<String,Object> jsonMap = (Map<String,Object>)JSON.deserializeUntyped(jsonStr);

System.debug('JSON :::'+jsonMap);

List<Object> langSkillsList = (List<Object>)jsonMap.get('langaugeskills');

System.debug('---->'+langSkillsList);

for(Object langStr:langSkillsList){

    System.debug((String)langStr);

}


output:



Reference:

https://salesforce-walker.blogspot.com/2021/04/json-parsing-using-map-sample.html

No comments:

Post a Comment

Grounding Prompt Templates with Apex Merge Fields

 Hi, You can include an Apex merge field in a prompt template to surface data retrieved from a SOQL query or an external API. Apex is also u...