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

Whealy, Chris chris.whealy@REDACTED
Wed Jun 27 10:43:39 CEST 2018


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180627/42c3800e/attachment.htm>


More information about the erlang-questions mailing list