arineng / jcr

JSON Content Rules Draft
1 stars 2 forks source link

is 42 == 42.0 #19

Open anewton1998 opened 8 years ago

anewton1998 commented 8 years ago

This was asked of me yesterday.

Given this JSON:

[ 42, 42 ]

Does that match this JCR (using old colon syntax ):

[ : 42, : 42.0 ]

or does it only match this JCR:

[ : 42, : 42 ]
codalogic commented 8 years ago

IMO, if the JCR is:

[ 42, 42 ]

Then the only valid JSON is:

[ 42, 42 ]

However, if the JCR (old style) is:

[ : 42.0, : 42.0 ]

then the following JSON is valid against it:

[ 42, 42 ]

So if you take your JSON and say that's your JCR, then you will only be matching integers. But if you specify floats, integers are subsets thereof.

anewton1998 commented 8 years ago

I'm good with that. We probably need to clarify that in the draft.

johnwcowan commented 8 years ago

I agree, but a more serious question is this. Given the JCR [9007199254740993.0], does the JSON [9007199254740992.0] match it? These are the two smallest positive integers that are indistinguishable when represented as floats. What about versions without the "point zero"?

codalogic commented 8 years ago

John, it's thorny issues like these that I'm glad you're contributing on. I would be happy to defer to you on this.

Also, if we did define an int64 (for example), would we represent that as a standard JSON number and say it's a requirement of a processor of this message format to handle it, or would we say that's bigger than what we'd normally expect a JSON processor to handle so we'll represent it as a string?