Sets plus JSON

Axel Rauschmayer axel at
Wed Oct 3 10:35:59 PDT 2012

> This also made me wonder about Maps, if the same use case were applied - toJSON simply wouldn't work when you have an object as a key. 

The default should probably be to convert to an object who’s keys are the results of applying String() to the map’s keys. Additionally, one could introduce a method toPairArray() that converts a Map into an array of pairs (2-element arrays) – that can be JSON-ified. The alternatives are:

1. Switch to pairs if the keys are not strings.
2. Allow a map to be configured which of the two representations should be used for toJSON.
3. Give toJSON a parameter whose default is to produce an object.

Given JSON.toStringify(), I’m not sure that #2 is necessary and that #3 is useful. #1 might work, but seems like a big change in representation and it takes time to check all the keys.

Dr. Axel Rauschmayer
axel at


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list