[erlang-questions] No JSON/MAPS interoperability in 17.0?

Richard A. O'Keefe <>
Mon Mar 17 02:52:08 CET 2014


On 15/03/2014, at 4:20 AM, Fred Hebert wrote:
> 1) it's not just a question of do floating point numbers survive the
>   roadtrip, but also integers.

The first couple of times I read through Javascript tutorials
and the ECMAscript specification, my expectation that any
serious language would support integers was so strong that
I completely failed to see that it doesn't.   This must make
life extremely "interesting" for people writing compilers 
that target Javascript. ...

RFC 7159 is explicit: integers up to ±(2**53-1) can be
expected to round-trip (probably, maybe) but no more.
And they cannot be expected to round-trip *as* integers,
but the values should (hopefully, arguably) survive.

> 2) json tags are more or less strings and expect utf-8. Currently, we
>   'support' utf8 atoms but we don't. See
>   http://www.erlang.org/erldoc?q=list_to_atom.
>   This doesn't mention what you do in case of trying to encode a map
>   which currently uses keys such as '1.0', 1.0, <<"1.0">>, and "1.0" at
>   the same time. We currently have 4 data types that will possibly need
>   an identical representation while being converted.
> 
>   Woops, that doesn't work super well and may in fact cover far less
>   than 99% of the cases. We have to consider all the other cases such
>   as just 1, 1.0, "1.00", "1.000", ..., and so on.

JSON is not a format for preserving arbitrary Erlang maps.
We can expect a JSON library that's map-aware to offer a
function

   json:can_handle(Term)

which will _reject_ any map where the keys are not
 - all atoms, or
 - all strings, or
 - all binaries that are valid as UTF-8.

After all, there are other things (like process IDs,
references, and functions) that don't translate to JSON.





More information about the erlang-questions mailing list