I'm getting a JSON array from a REST callout:


This gives me an error:

 List<Object> objs = (List<Object>)JSON.deserializeUntyped(res.getBody());

FATAL_ERROR System.TypeException: Invalid conversion from runtime type String to List

Ouch. Did I serialize the JSON incorrectly, or am I doing a mistake at covnerting the JSOn to the List?


1 Answer 1


Looks like the payload got serialized twice somehow. Ideally you would fix that so it is serialized just once instead. However, you can fix it in the interim by deserializing first into a String, then into your List<Object>.

String payload = (String)JSON.deserializeUntyped(response.getBody());
List<Object> data = (List<Object>)JSON.deserializeUntyped(payload);
  • Thanks a lot, you were right! May I ask how you figured this out? It does not seem obvious to me.
    – DevelBase2
    Mar 4, 2022 at 21:33
  • 1
    @DevelBase2 The escaped double-quotes is indicative of this type of thing. "regular" JSON doesn't do that, it'd just be [{"name":"Jan0","lastName":"Test0","id":0} ...]
    – Derek F
    Mar 4, 2022 at 21:35
  • @DerekF Hah, brilliant. Thanks!
    – DevelBase2
    Mar 4, 2022 at 21:36

You must log in to answer this question.

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