hankhero / cl-json

Json encoder and decoder for Common-Lisp
Other
75 stars 39 forks source link

Decoding error #16

Open eadmund opened 8 years ago

eadmund commented 8 years ago

Per the ECMAScript spec, Section 15.12.2, at the bottom of pg. 204 'In the case where there are duplicate name Strings within an object, lexically preceding values for the same key shall be overwritten.' This behaviour is relied upon by RFC 7517, e.g. Section 5 'The member names within a JWK Set MUST be unique; JWK Set parsers MUST either reject JWK Sets with duplicate member names or use a JSON parser that returns only the lexically last duplicate member name, as specified in Section 15.12 ("The JSON Object") of ECMAScript 5.1 [ECMAScript].

However, cl-json returns both values for a duplicate key:

(json:decode-json-from-string "{\"foo\": 1, \"foo\": 2}") ((:foo . 1) (:foo . 2))

I think it'd be possible to hack something together with a customised decoder, but it's probably better to handle this by default.