A response body is a String until you parse it. JSON.deserializeUntyped turns that
String into Apex values, and the shape of those values is not quite what you would
guess from the JSON you sent.
The top level decides what the parser hands back: a JSON object becomes a
Map<String, Object> and a JSON array becomes a List<Object>. Inside the map,
every value is an Object, and each one carries the type the JSON gave it.
Map<String, Object> product = (Map<String, Object>) JSON.deserializeUntyped(body);
String title = (String) product.get('title');
Boolean inStock = (Boolean) product.get('inStock');
Here is the part that catches people. A JSON number is ALWAYS a Decimal in Apex,
whether it is 99 or 9.99 or 15.14. It is never an Integer, even when the
number has no decimal point.
Decimal stock = (Decimal) product.get('stock');
Decimal price = (Decimal) product.get('price');
Reading a number as an Integer fails at runtime, and the message points at the
cast rather than at the JSON:
Integer price = (Integer) product.get('price'); // System.TypeException
The cast is only accepted when the number was written without a decimal point at
all, so the very same line works for a stock count and blows up for a price. It
also blows up for 100.0, because the number carries a decimal point even though
its value is whole.
A JSON object inside the JSON object is another Map<String, Object>. You have to
cast it before you can read its keys, because get on the outer map hands you an
Object and not a map.
Map<String, Object> product = (Map<String, Object>) JSON.deserializeUntyped(body);
Map<String, Object> dimensions = (Map<String, Object>) product.get('dimensions');
Decimal height = (Decimal) dimensions.get('height');
get returns null for a key that is not in the JSON, and for a key whose value is
JSON null. Nothing throws, so a null is easy to miss until you use it.
The three mistakes that cost the most time: reading a number as an Integer,
reading a nested object without casting it to a map, and using a value straight out
of get without casting it to the type you need. That last one bites hardest,
because a Decimal in a comparison needs the cast as well, and an Object cannot
be compared at all.