Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If symbols of an object cannot be iterated over, does that mean they cannot be serialized into JSON? Also a symbol doesn't have a unique string representation, Symbol('foo') != another Symbol('foo'), does that mean they cannot be deserialized from JSON?


JSON is a very specific subset of JavaScript, and there is no literal syntax for Symbols, so there is no defined way to represent a symbol at the moment. Unless you wanted to encode them as a function call or something, which sounds terrible.


I don't think they can be represented in JSON. There are already other JS primitive types that can't be represented in JSON (Date) so at least it isn't introducing any inconsistency... JSON is only a subset of JS objects.


Not by default. But because there are possible overlaps in keys represented as strings it probably wouldnt be too helpful. Otherwise you could write your own .toJSON method to iterate over the symbol set if you really wanted to.


I don't know how the default JSON serializers/deserializers work, but I suspect that wouldn't work with symbols. You could probably get something working with Symbol.for().




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: