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

Agentforce metadata types for deployment

 Hi, The following are key metadata types to consider when deploying Prompt Templates, Topics, Agent Actions, and Agents in Salesforce. <...