Mandeep Singh
Mandeep Singh

Reputation: 308

Library to convert JSON string to Erlang record

I've a large JSON string, I want to convert this string into Erlang record. I found jiffy library but it doesn't completely convert to record.

For example: jiffy:decode(<<"{\"foo\":\"bar\"}">>). gives

{[{<<"foo">>,<<"bar">>}]}

but I want the following output:

{ok,{obj,[{"foo",<<"bar">>}]},[]}

Is there any library that can be used for the desired output?

Or is there any library that can be used in combination of jiffy for further modifying the output of it.

Consider the fact the JSON string is large, and I want the output is minimum time.

Upvotes: 2

Views: 1281

Answers (1)

Jr0
Jr0

Reputation: 2173

Take a look at ejson, from the documentation:

JSON library for Erlang on top of jsx. It gives a declarative interface for jsx by which we need to specify conversion rules and ejson will convert tuples according to the rules.

I made this library to make easy not just the encoding but rather the decoding of JSONs to Erlang records...

In order for ejson to take effect the source files need to be compiled with parse_transform ejson_trans. All record which has -json attribute can be converted to JSON later.

Upvotes: 2

Related Questions