I have the following json :
{ "users": [{ "user": { "user_id" :"a11uhk22hsd3jbskj", "username" :"tom", "location" : null } }] }
I get this json in response to a request to an api. Looking at the doc for this api, location is supposed to be an array (containing geodata, latitude, longitude address etc).
Now the question is : there's an error in the json? I mean, location doesn't seems,to me, to be an array, or is possible to represent a null array in that way? and if yes what is the difference between :
"location" : null "location" : []
Thanks in advance
JSON data has the concept of null and empty arrays and objects.
In Spark 3.0 and above, the JSON parser does not allow empty strings. An exception is thrown for all data types, except BinaryType and StringType .
Strings, Booleans and integers do not have an 'empty' form, so there it is okay to use null values.
JSON can actually take the form of any data type that is valid for inclusion inside JSON, not just arrays or objects.
"location" : null // this is not really an array it's a null object "location" : [] // this is an empty array
It looks like this API returns null when there is no location defined - instead of returning an empty array, not too unusual really - but they should tell you if they're going to do this.
null
is a legal value (and reserved word) in JSON, but some environments do not have a "NULL" object (as opposed to a NULL
value) and hence cannot accurately represent the JSON null
. So they will sometimes represent it as an empty array.
Whether null
is a legal value in that particular element of that particular API is entirely up to the API designer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With