I am trying to get a value from the JSON response and add it to an External Object field. How to do that with a JSON response with nested objects.

Example of the JSON response:

"predictions": {
            "winner": {
                "id": 1189,
                "name": "Deportivo Santani",
                "comment": "Win or draw"

What to put instead of the Apex code question marks below for the id of the winner?

row.put('predictions_winner_id', string.valueOf(newRow.get('???')));

Any help would be appreciated. Thank you!

1 Answer 1


To extract the id of the winner from the nested JSON object and add it to an External Object field in Apex, you can use the JSON.deserializeUntyped() method to parse the JSON string into a map and then navigate through the nested structure.

Here's how you can do it:

// Assuming 'jsonString' contains the JSON response
Map<String, Object> jsonMap = (Map<String, Object>) JSON.deserializeUntyped(jsonString);
Map<String, Object> predictions = (Map<String, Object>) jsonMap.get('predictions');
Map<String, Object> winner = (Map<String, Object>) predictions.get('winner');
Integer winnerId = (Integer) winner.get('id');

// Now you can put the winnerId into the External Object field
row.put('predictions_winner_id', String.valueOf(winnerId));

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .