JSON deserializeUntyped using Apex in Salesforce

JSON deserializeUntyped using Apex in Salesforce

Sample Code:

String strJSON = '{"items":[{"Date Field":"01-01-1999","Prototype Settings":"PS3","Hardware Type":"Type1","Overall Status":"In Progress","Source":"Web"},{"Date Field":"18-05-1999","Prototype Settings":"PS6","Hardware Type":"Type3","Overall Status":"Completed","Source":"Email"}]}';
Map < String, Object > fullMap = ( Map < String, Object > )JSON.deserializeUntyped( strJSON );
for ( Object obj : ( List< Object > )fullMap.get( 'items' ) ) {
   
    Map < String, Object > m = ( Map < String, Object > )obj;
    system.debug( 'Date Field is ' + m.get( 'Date Field' ) );//This is object. Use (String) to convert it to String
    system.debug( 'Prototype Settings is ' + m.get( 'Prototype Settings' ) );
    system.debug( 'Hardware Type is ' + m.get( 'Hardware Type' ) );
    system.debug( 'Overall Status is ' + m.get( 'Overall Status' ) );
    system.debug( 'Source is ' + m.get( 'Source' ) );
   
}

Output:

Leave a Reply