jsx icon indicating copy to clipboard operation
jsx copied to clipboard

strict option: no_duplicate_keys

Open andreineculau opened this issue 7 years ago • 5 comments

as per https://tools.ietf.org/html/rfc7159#section-4

The names within an object SHOULD be unique.

yet JSX works like this:

1> jsx:decode(<<"{\"a\": \"b\", \"a\": \"c\"}">>).
[{<<"a">>,<<"b">>},{<<"a">>,<<"c">>}]

Consider adding no_duplicate_keys as as flag part of the strict option, or similar.

andreineculau avatar Dec 15 '16 17:12 andreineculau

i'll look at adding this to the in progress 3.0

probably won't backport it to 2.x tho, because there's no low impact way to track multiple keys when decoding to a map

talentdeficit avatar Dec 18 '16 04:12 talentdeficit

how is "there's no low impact way..." relevant if we're talking about adding a flag? current performance can stay the same, but those who want no_duplicate_keys can deal with whatever "performance" loss?

andreineculau avatar Dec 24 '16 16:12 andreineculau

a friendly bump. what's the status on this? thanks!

andreineculau avatar Jan 19 '18 23:01 andreineculau

@andreineculau: is this still an issue (it's been more than 2 years)? How would you go about detecting the duplicates? I imagine a map, since a list would be even more performance-degrading. Is this what you mean by your question? You'd like a flag and then a runtime validation if that flag was active. Is that it?

paulo-ferraz-oliveira avatar Sep 12 '20 01:09 paulo-ferraz-oliveira

@paulo-ferraz-oliveira I missed your comment, sorry. But yes, I think it's still an issue.

[email protected] behaviour is unchanged

1> jsx:decode(<<"{\"a\": \"b\", \"a\": \"c\"}">>).
#{<<"a">> => <<"c">>}
2> jsx:decode(<<"{\"a\": \"b\", \"a\": \"c\"}">>, [{return_maps, false}]).
[{<<"a">>,<<"b">>},{<<"a">>,<<"c">>}]

from [email protected]

1> jsx:decode(<<"{\"a\": \"b\", \"a\": \"c\"}">>).
[{<<"a">>,<<"b">>},{<<"a">>,<<"c">>}]
2> jsx:decode(<<"{\"a\": \"b\", \"a\": \"c\"}">>, [{return_maps, true}]).
#{<<"a">> => <<"c">>}

For starters, it would be good if there's no behaviour difference dictated by return_maps. At this point, it is "better" to return_maps: false and do the validation outside of JSX, because when returning maps, there's simply no way to detect duplicate keys.

andreineculau avatar Jun 01 '21 05:06 andreineculau