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

Thomas Lindgren <>
Fri Jan 18 14:55:01 CET 2013



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). Thus, to find the value of a given key you need in principle to parse the whole object anyway. This makes SAX less convenient, though using it might still save memory. 

If you know repeated keys will never happen (the JSON RFC says "The names within an object SHOULD be unique."), you could roll the dice and go ahead anyway.

Best,
Thomas


>________________________________
> From: Yash Ganthe <>
>To: erlang-questions <> 
>Sent: Friday, January 18, 2013 1:18 PM
>Subject: [erlang-questions] SAX-like JSON Parser for Erlang
> 
>
>SAX allows the client application to read an XML piece-by-piece. This is different than DOM which expects the entire XML to be loaded in memory. SAX is thus useful for reading very large XML documents.
> 
>Mochijson is a good JSON parser which emits structs that correspond to individual JSON strings. It however expects the entire JSON string to be given to its functions.
>If I have about 10000 records in an JSON such as this,
>{ "d" : 
>[
>                {
>                                "ID": 1, "Name": "p1", "Email": ""
>                }, 
>                {
>                                "ID": 2, "Name": "p2", "Email": ""
>                }, 
>                {
>                                "ID": 3, "Name": "p3", "Email": ""
>                }, 
>                {
>                                "ID": 4, "Name": "p4", "Email": ""
>                } . . . . .
>] }
>the entire JSON string would have to be first obtained and then passed to mochijson/mochijson2.
> 
>I am looking for a way to let the module give me one record at a time from the large JSON-formatted array. Is there any module that lets us do this?
> 
>Thanks,
>Yash
>_______________________________________________
>erlang-questions mailing list
>
>http://erlang.org/mailman/listinfo/erlang-questions
>
>
>



More information about the erlang-questions mailing list