Sets plus JSON

Brendan Eich brendan at mozilla.org
Thu Oct 4 17:51:24 PDT 2012


Rick Waldron wrote:
> On Thu, Oct 4, 2012 at 8:16 PM, Brendan Eich <brendan at mozilla.org 
> <mailto:brendan at mozilla.org>> wrote:
>
>     Nicholas C. Zakas wrote:
>
>         I agree, I'm not sure there is a rational default for Map, but
>         I think there is one for Set as an array (and it seems like
>         most people agreed).
>
>
>     As with Set, I claim the default JSON for Map should be
>
>       [[key1, value1], ~~~ [keyN, valueN]]
>
>
>
> I'm still curious about my question from yesterday; instead of 
> repasting, I put it in a gist:
>
> https://gist.github.com/3837337

If the Map serializes as [[k1, v1], ~~~ [kN, vN]] then the deserializer 
could risk interpreting such as a Map. Better would be for the 
serializer to make the Map encoding the *value* of a by-convention key 
whose name implies the value is a Map serialization.

Still a level up from core JS, but as Allen said, that's part of the 
equation. This is not a core-language serialization-via-JSON protocol, 
because JSON is frozen as-is for all time.

/be
>
>
> Rick
>
>
>     with ~~~ as meta-ellipsis.
>
>     This is not a round-tripping seralization, any more than
>
>       [elt1, ~~~ eltN]
>
>     is for Set. It simply is the normal form expected by the Map
>     constructor. That wins.
>
>     /be
>
>     _______________________________________________
>     es-discuss mailing list
>     es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
>     https://mail.mozilla.org/listinfo/es-discuss
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list