[erlang-questions] New project: ZJ - A tiny JSON encoder/decoder

Dmitry Kolesnikov dmkolesnikov@REDACTED
Tue Jun 26 15:44:08 CEST 2018


Hello,

It looks promising, thank you for sharing!

However, I’d like to suggest to consider mapping `null -> null`.
I’ve been raising a similar issue to jsx as well.

The atom `undefined` is used by many library to express undefined result.
Please consider its usage

JSON -> Erlang:
* null -> undefined

Erlang -> JSON
* undefined -> null

Best Regards,
Dmitry


> On 26 Jun 2018, at 12.58, zxq9@REDACTED wrote:
> 
> With tuple calls gone and mochijson2 finally going extinct I found myself in need of a strings-as-strings JSON encoder/decoder in pure Erlang (not NIF-based). I wrote one yesterday. It is a single module that exports two functions: encode/1 and decode/1. Erlang didn't really *need* another JSON encoder/decoder, of course, but this one works exactly the way I need -- if anyone else finds it useful you're welcome to it:
> 
> https://gitlab.com/zxq9/zj
> 
> A few tradeoffs have to be made when writing a JSON encoder/decoder because JSON types don't map very well with Erlang, and everyone has different optimal performance profiles and data idioms within their programs. The mappings ZJ follows are below. Note that tuples map to JSON arrays, which means proplists do NOT map to JSON objects, Erlang maps do.
> 
> JSON -> Erlang:
> * Integer -> Integer
> * Float   -> Float
> * String  -> String
> * Object  -> Map
> * Array   -> List
> * true    -> true
> * false   -> false
> * null    -> null
> 
> Erlang -> JSON:
> * Integer -> Integer
> * Float   -> Float
> * Map     -> Object
> * List    -> Array
> * Tuple   -> Array
> * Binary  -> String
> * UTF-8   -> String
> * true    -> true
> * false   -> false
> * null    -> null
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180626/ceab8603/attachment.bin>


More information about the erlang-questions mailing list