[erlang-questions] SAX-like JSON Parser for Erlang

Thomas Lindgren thomasl_erlang@REDACTED
Tue Jan 22 13:41:11 CET 2013





----- Original Message -----
> From: Richard O'Keefe <ok@REDACTED>
> To: Thomas Lindgren <thomasl_erlang@REDACTED>
> Cc: erlang-questions <erlang-questions@REDACTED>
> Sent: Tuesday, January 22, 2013 6:51 AM
> Subject: Re: [erlang-questions] SAX-like JSON Parser for Erlang
> 
> 
> On 19/01/2013, at 2:55 AM, Thomas Lindgren wrote:
> 
>> 
>> 
>>  One potential problem with SAX-style parsing is that repeated keys in a 
> JSON object will use/return only the last value (a behaviour inherited from 
> javascript, I believe).
> 
> When implementing a JSON parser, I found the JSON specification
> silent about this and asked for clarification.  Taking the last
> value for repeated keys is *NOT* a defined property of JSON nor
> is it something you can expect as a de-facto standard.  Some
> parsers will take the first value.  Some will take the last one.
> Some will raise a sensible exception.  Some a non-sensible one.

Could you give a reference to that clarification? It could be useful in upcoming discussions.

Taking the RFC at face value, it seems the behaviour is unspecified (since it only says the use of repeated keys is discouraged). As far as I'm aware, though, the common expectation would be that the decoder behaves "like javascript". I've seen some proposed usage that relies on the parser handling duplicate keys (without throwing exceptions). See the fairly recent node.js mailing list archives.

Best,
Thomas




More information about the erlang-questions mailing list