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

Marc Worrell marc@REDACTED
Wed Jun 27 10:05:04 CEST 2018


I agree with mapping ‘null' to ‘undefined' and vice versa.

An issue with ‘null’ in JavaScript versus Erlang is that in JavaScript ‘null’ does have meaning.
In Erlang it is just another random atom.

Consider in JavaScript:

> if (null) console.log('yeah');
< undefined
> if (!null) console.log('yeah');
[Log] yeah

In Erlang libraries only ‘undefined’ is handled.
If you need to interface the received JSON to Erlang then you need to either
change the libraries or add mapping code.

To me it seems to be pragmatic to let the decoder use ‘undefined’ instead of ‘null’.

- Marc
 

> On 27 Jun 2018, at 09:42, Michael Nisi <michael.nisi@REDACTED> wrote:
> 
> Here’s how v8::JSON, the JSON parser in Node’s JavaScript engine, does it:
> 
>> JSON.stringify({})
> '{}'
>> JSON.stringify({ name: null })
> '{"name":null}'
>> JSON.stringify({ name: undefined })
> '{}'
>> JSON.stringify({ name: 'Lionel' })
> '{"name":"Lionel"}’
> 
>> JSON.parse('{}').name
> undefined
>> JSON.parse('{ "name": null }').name
> null
> 
> JavaScript differentiates between null and undefined, without wanting to get philosophical here.
> 
> Michael
> 
> 
>> On 27. Jun 2018, at 09:21, zxq9@REDACTED wrote:
>> 
>> Erlang -> JSON
>> - true      -> true
>> - false     -> false
>> - undefined -> null
>> - Atom      -> String
>> 
>> JSON -> Erlang
>> - true  -> true
>> - false -> false
>> - null  -> undefined
>> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list