We're creating our JSON responses to my salesforce callouts in house, so I'm guessing the issue has to do with how we're representing NULL in the JSON response. Here's a snippet of the response SF gets:
{"recordCount":5559,"records":[{"LaunchCount":"1","Country":NULL,"AccountSalesforceID":"0018000000anaaK","YearStart":"2014"}
Note the NULL value for Country, which isn't a string because it isn't in quotes. That seemed to be the proper way to do it from what I've seen online, but attempting to map response using JSON.deserializeUntyped got me the 'unrecognized token' error. Replacing null with any string, including "null", fixes the error.
So is my issue with not correctly representing NULL in my JSON, or is this an issue with the salesforce deserialize method?
Best Answer
In JavaScript/JSON
null
is defined butNULL
isn't. Trynull
. (Which is different from"null"
or'null'
which are strings.)I just checked and Apex's
JSON.deserializeUntyped
throwsSystem.JSONException: Unrecognized token 'NULL'
forNULL
but works withnull
i.e. it is (not to surprisingly) consistent with JavaScript/JSON.