JSON.stringify and symbols

Frankie Bagnardi f.bagnardi at gmail.com
Mon Jun 30 17:01:48 PDT 2014


It also skips explicit undefined values.  Basically, if there's no good
JSON representation of something, it pretends it doesn't exist.

You can also get this behavior by doing `obj.toJSON = () => undefined`
[example fiddle][1]

In all of those cases symbols behave as if they were the value `undefined`,
or an object with a toJSON which returns undefined.

[1]: http://jsfiddle.net/MRUj6/


On Mon, Jun 30, 2014 at 12:55 PM, Mark S. Miller <erights at google.com> wrote:

> JSON.stringify also skips function-valued properties, which seems even
> more weird. I think this is fine as long as it can be overridden by
> replacers and resolvers.
>
>
>
> On Mon, Jun 30, 2014 at 11:37 AM, Jason Orendorff <
> jason.orendorff at gmail.com> wrote:
>
>> As specified in the latest draft:
>>
>> 1. JSON.stringify(symbol) returns undefined.
>>
>> 2. JSON.stringify([symbol]) returns "[null]".
>>
>> 3. JSON.stringify(object) skips any symbol-keyed properties on the object.
>>
>> So far, so good, I guess. A little wonky maybe, but JSON doesn't have
>> symbols, so sure.
>>
>> This struck me as funny though:
>>
>> 4. JSON.stringify(object) also skips symbol-valued properties.
>>
>> That is, JSON.stringify({"x": Symbol()}) == "{}". I don't know that
>> there's anything more useful it should be doing instead. Thoughts?
>>
>> -j
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
>
> --
>     Cheers,
>     --MarkM
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140630/8d4e0d83/attachment.html>


More information about the es-discuss mailing list