Passing data works well as JSON but documents works better as XML where you can use XML Schema.
Passing data works well as JSON but documents works better as XML where you can use XML Schema.
Even though JSON is a "natural" for scalar types, it can get weird, there. For example, let's say we have a float:
{ "kids": 1.0 }
It needs to be parsed as a float, because we could have: { "kids": 2.3 }
But I often see these sent as: { "kids": 1 }
or { "kids": "1.0" }
or even { "kids": "1" }
And I have differing results, based on the parser. JSON.stringify(JSON.parse('{"kids":10000000000000001}')) -> '{"kids":10000000000000000}'
How do JSON schemas handle "must be an integer", and having to pass a string to get the necessary value? {“kids”: 12345678901234567890123456789012345678901234567890}
is perfectly legal json.In XML, every attribute or text fragment is a string, to be POSSIBLY parsed as a string, integer, date etc. according to what applications choose to do (usually according to an explicit schema).
In JSON, YAML, etc. there are at least integers, strings and floating point numbers, introducing arbitrary representation choices (1, 1.0, "1", "1.0") and implementation artifacts (e.g. numerical limits).
So, no better than XML really :D
With a custom extension to the json-schema adding property bsonType:long, instead of type:int. Along with a few other data types like datetimes, uuid, regex. It can be integrated with custom hooks in many schema validators.