datalanche / json-bignum

Node.js JSON replacement which handles 64-bit integers and arbitrary-precision decimals.
MIT License
24 stars 5 forks source link

Add `allowDuplicateProperties` parsing option. #1

Closed brianr closed 11 years ago

brianr commented 11 years ago

While discouraged, the JSON spec does allow the same property to be present more than once in an object [1]. The built-in node.js JSON parser allows them, but json-bignum previously did not. This option (default false, same behavior as before) makes json-bignum behave the same way as JSON in this respect.

For example, consider the following JSON string:

{"hello": "world1", "hello": "world2"}

With allowDuplicateProperties == false, parsing above will throw a SyntaxError. When true, it will return:

{"hello": "world2"}

Feedback welcome; I'm a little nervous sending this without any tests.

[1] See section 2.2: "The names within an object SHOULD be unique." http://www.ietf.org/rfc/rfc4627.txt

rpedela commented 11 years ago

Thanks for the pull request!

I would like this module to behave just like the built-in JSON functions except they handle 64-bit integers and large decimals correctly. I am thinking we should just allow duplicate properties by default. What do you think?

brianr commented 11 years ago

Sounds good to me. I've updated the commit to make allowDuplicateProperties default to true.

brianr commented 11 years ago

Arg, this doesn't actually default to true. Fix on the way.

rpedela commented 11 years ago

No worries. Thanks for the pull request and fix.