[erlang-questions] JSON Parser

Bob Ippolito bob@REDACTED
Wed Jul 15 20:24:39 CEST 2015


Records are a compile time construct, so in order to parse as records
you'd need to define the records in advance and provide a schema and record
definition to the parser for the document. This could be done in a layer
above the JSON parser.

Maps are the data structure you're looking for. Most of the JSON
implementations provide backwards compatibility to versions of Erlang
before maps, so other data structures (such as dicts or proplists) are more
common.

On Wednesday, July 15, 2015, Kannan <vasdeveloper@REDACTED> wrote:

> Is any of them supporting Erlang 'record' as their base for
> encoding/decoding. I see many of them are doing it with just list of tuples
> of binaries.Erlang records best match the structure of JSON format.
>
> JSON
> ----------
> {"name": "Theepan",
>   "work": "Coding",
>   "salary": "0"
> }
>
> Matching Erlang record
> -----------------------------------
> -record( json_record,
> {
>   'name' = "Theepan",
>   'work' = "Coding",
>   'salary' = "0"
> }
> }
>
> Thanks,
> Theepan
>
> On Wed, Jul 15, 2015 at 2:33 PM, Jesper Louis Andersen <
> jesper.louis.andersen@REDACTED
> <javascript:_e(%7B%7D,'cvml','jesper.louis.andersen@REDACTED');>> wrote:
>
>>
>> On Tue, Jul 14, 2015 at 10:06 PM, Kannan <vasdeveloper@REDACTED
>> <javascript:_e(%7B%7D,'cvml','vasdeveloper@REDACTED');>> wrote:
>>
>>> I come across many JSON libraries. Once from MochiWeb, Other one from
>>> Yaws. Third one from CouchDB. And some others through Googling.
>>>
>>
>> There are two very popular JSON parsers in Erlang: jsx and jiffy.
>>
>> jsx is written in plain Erlang. It is fast, correct and since it is
>> written in Erlang, it will also automatically yield for other processes in
>> the system.
>>
>> jiffy is written as a C NIF. It is about 10 times faster than jsx, but
>> the caveat is everything that has to do with C NIFs: blocking a scheduler,
>> C code having errors, security considerations, etc.
>>
>> I tend to run with `jsx` in my projects, and then I switch away from JSON
>> when it gets to slow. JSON is a bad format that should never have existed
>> in the first place. We are stuck with it because it's historic alternative,
>> XML, was far worse in every aspect.
>>
>>
>> --
>> J.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150715/c72357f9/attachment.htm>


More information about the erlang-questions mailing list