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

Loïc Hoguin essen@REDACTED
Wed Jun 27 10:56:52 CEST 2018


You are conflating Javascript and JSON. JSON was originally defined as a 
subset of Javascript, but it has very little to do with it otherwise.

There is no 'undefined' JSON type. There is only 'null'. The Javascript 
'undefined' is irrelevant because it doesn't translate into JSON to 
begin with.

That being said, both the Javascript 'undefined' and 'null' translate to 
the JSON 'null'. They are not treated as distinct. The JSON 'null' has 
roughly the same semantics as the Erlang 'undefined' so the mapping 
makes sense and makes using JSON libraries easier as long as the JSON 
library uses maps and not proplists.

Cheers,

On 06/27/2018 10:43 AM, Whealy, Chris wrote:
> Allow me to elaborate on your point Michael (also without getting 
> philosophical).
> 
> In JavaScript null and undefined are identifiably distinct datatypes 
> that serve specific purposes:
> 
>   * *null* - This variable specifically has no value
>   * *undefined* - The value of this variable is indeterminate (I.E.
>     identifiably different from null)
> 
> 
> Although the atom null has no special meaning in Erlang, it does when 
> mapped to JavaScript null; therefore to maintain accuracy, Erlang devs 
> who also work in JavaScript should understand and preserve this semantic 
> difference.  Likewise with Erlang undefined mapping to JavaScript undefined.
> 
> Therefore, I submit that this semantic difference should be persevered 
> when mapping from Erlang to JavaScript, otherwise data loss will occur, 
> particularly when mapping from JavaScript back to Erlang.
> 
> Erlang    -> JavaScript
> null      -> null
> undefined -> undefined
> 
> JavaScript -> Erlang
> null       -> null
> undefined  -> undefined
> 
> This part of the mapping table at least should be bijective.
> 
> *Chris Whealy*
> 
> SAP Cloud Platform | Strategy & Product Management | Team
> 
> *SAP UK Ltd,* Clockhouse Place, Bedfont Rd, Feltham, Middx, TW14 8HA, 
> England
> 
> M +44 (0)7808 575377
> 
> Find out more on the Strategy & Product Management***Wiki page* 
> <https://wiki.wdf.sap.corp/wiki/pages/viewpage.action?pageId=1865737441> (SAP 
> internal)
> Follow our latest activities in SAP CP User Community *Jam Group 
> <https://jam4.sapjam.com/groups/about_page/eopqUq5S182gY7JFrbdwis>*
> 
> Please consider the impact on the environment before printing this e-mail.
> 
> Twitter: @LogaRhythm
> /"The voice of ignorance speaks loud and long,/
> /  but the words of the wise are quiet and few"/
> /                                                 Ancient Proverb/
> 
> 
> 
> 
> 
>> On 27 Jun 2018, at 08:42, Michael Nisi <michael.nisi@REDACTED 
>> <mailto: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 <mailto: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 <mailto:erlang-questions@REDACTED>
>> http://erlang.org/mailman/listinfo/erlang-questions
> 
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
> 

-- 
Loïc Hoguin
https://ninenines.eu



More information about the erlang-questions mailing list