JSON: Cannot deserialize instance of date from VALUE_STRING

  • I'm officially breaking up with Salesforce Date parsing. This has got to be the most frustrating thing.

    I have the following date in a JSON string (full JSON below):


    But when I try to deserialize the data:

    Opportunity[] results = (List<Opportunity>)JSON.deserialize(res, List<Opportunity>.class);

    I get the following error:

    System.JSONException: Cannot deserialize instance of date from VALUE_STRING value 2016-12-05T16:19:44.000Z

    I have looked at so many date parse issues before and from what I've gathered it must be in ISO 8601 - though ISO 8601 can take various shapes: Ruby Docs: ISO 8601

    All of the following seem to recommend exactly what I've done

    Cannot deserialize instance of datetime from VALUE_STRING value




    How should I format this date string?

    Thank you!

    Full JSON string:

  • sfdcfox

    sfdcfox Correct answer

    5 years ago

    Three problems here:

    (a) Date receiving DateTime value.

    The value should be "YYYY-MM-DD" only.

    (b) Decimal receiving String value.

    The value should not be in quotes.

    (c) You must not have a trailing comma.

    JSON-compliant strings are more strict than normal JavaScript.


    Making the change to Date instead of DateTime fixed it. Thanks man!

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM