Description
Prerequisites
- I have read the documentation
What theme are you using?
core
What is your question?
With the JSON being more and more used for data exchange instead XML, addition of JSON schema is welcomed, as for XML there are XSD schemas.
By asking the team that wrote the RFC8259 about encoding null values in JSON, during discussions we came also to JSON-schema.
By consulting the documentation and the examples provided here for strings, numeric types, arrays etc, :
https://json-schema.org/understanding-json-schema/reference/string.html
https://json-schema.org/understanding-json-schema/reference/numeric.html
https://json-schema.org/understanding-json-schema/reference/array.html
... I do not understand why examples with null values are not provided, as their inclusion is quite critical.
I will try to provide an example:
Let's consider that a car is sending every 10 seconds the following data in JSON format:
- GPSLocation as an array with Latitude and Longitude, accepting also null values ("nullableArray")
- Speed as a number, accepting also null values ("nullableNumber")
- Temperature as a number accepting also null values ("nullableNumber")
- TimeStamp as a string accepting also null values ("nullableString")
- AdditionalInformation as a string accepting also null values ("nullableString").
"nullableArray": {"title": "Nullable Array","type": ["null","array"],"default": null}
"nullableNumber": {"title": "Nullable Number","type": ["null","number"],"default": null}
"nullableString": {"title": "Nullable String","type": ["null","string"],"default": null}
Lets's consider that all these elements should be provided in JSON even if they are not available (i.e. in a tunnel GPSLocation and Speed are not available, AdditionalInformation is usually not available), so a JSON without null elements, will not be ok:
{"Temperature":12.3 , "TimeStamp: "2023-01-17T19:37:52.1234Z"}
In this context can you confirm that a JSON that will look like this can be described by using JSON-Schema and is encoded OK
{"GPSLocation":null , "Speed":null , "Temperature":12.3 , "TimeStamp: "2023-01-17T19:37:52.1234Z" , "AdditionalInformation": null.}
... but a JSON that looks like this is not encoded correct:
{"GPSLocation":"null": , "Speed":"null" , "Temperature":12.3 , "TimeStamp: "2023-01-17T19:37:52.1234Z" , "AdditionalInformation": "null".}
If so, then please consider to add examples with null as a invalid value for strings, numeric types, arrays etc and with "null" as an invalid value for numeric types and arrays. I assume "null" should be invalid for strings as well, as it is a reserved word, or at least to be clear that providing "null" does not mean that the value is null, but it means that a string with 4 characters was provided, so if the JSON will be imported in a database, the default behavior will be the insertion of "null" string instead of letting that attribute NULL.
In relation to null values in numeric, if "Speed":null is transformed into "Speed":0, according to examples and documentation provided, this would be wrong, as the speed is not zero, but is not available. If Speed will be provided as zero instead null, statistics made in BI will be wrong.
In relation to null values in strings, if "AdditionalInformation":null is transformed into "AdditionalInformation":"" this would be wrong as Empty String <> Null and counting how many records having AdditionalInformation may be computed wrongly in BI.
In relation to dateTime attributes, there are no examples including milliseconds, neither with UTC time (Zulu).
Thank you,
Iurie Maxim