resource / Front-End-Standards

Front-end development standards for Resource.
MIT License
23 stars 1 forks source link

JSON: Error in "items" collection example #38

Closed Krxtopher closed 11 years ago

Krxtopher commented 11 years ago

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.

// example
{
    "method": "GET",
    "id": 08819019273097,
    …
nicetransition commented 11 years ago

Good catch, this should be updated 100%... @LukeAskew

LukeAskew commented 11 years ago

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?

nicetransition commented 11 years ago

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

Krxtopher commented 11 years ago

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. :)

nicetransition commented 11 years ago

This makes me think we should create a call out for when to make a value a string vs. boolean vs. string vs. array

Krxtopher commented 11 years ago

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:

nicetransition commented 11 years ago

all excellent call outs