Closed Krxtopher closed 11 years ago
Good catch, this should be updated 100%... @LukeAskew
Did not know about the leading zero thing. Link to spec for reference: http://www.w3.org/TR/json-ld/#dfn-number
This brings up the question of how to preserve leading zeros in APIs. Do we suggest using strings in these instances? Then using coercion if needed?
To my knowledge, you can only do leading zeros as a string -- the moment you do any math to it though (or use it as a number) it goes away
Kevin is correct. If you need to preserve leading zeros you have to use a string and you should only treat it as a string. That means no math. If you think you require both leading zeros and math then you are trying to use a single value as two different types (and for two different roles). It is a bad idea for a property to have an identity crisis. :)
This makes me think we should create a call out for when to make a value a string vs. boolean vs. string vs. array
Well, I think going into that level of detail starts to change this from a "standards" document to an encyclopedia on application design and programming principles. In my view a good standards document/style guide should limit its scope as follows:
for
loops are good examples.all excellent call outs
The example under 'use an "items" collection to store sets of like data' contains a pseudo numeric "id" value which contains a leading 0. This is not technically allowed in the JSON spec and probably isn't what the original author intended anyway. The example should either wrap the value in quotes or omit the leading 0.