4 ms·
There’s no concept of mutability in JSON. A JSON parser could give you immutable arrays and maps if it wanted to.
by chrisseaton 6y ago
There’s no concept of mutability in JSON. A JSON parser could give you immutable arrays and maps if it wanted to.
- resonantjacket5 6y agoYes, but json by itself doesn't actually do anything. It'd always be used in context of javascript/python/ etc.. As I said you could interpret it as a tuple or I guess a frozen array for javascript? I don't think there is a native immmutable array in javascript. If it's a map I'm a bit more unsure how you'd check to find the object (quickly). You're basically getting into the how to store a struct/class as a map key. Either way its a bit more involved than just having json parser return an immutable array and map, and the more I think about it the more edges cases there are.
- recursive 6y ago> I don't think there is a native immmutable array in javascript. I'm here to tell you that `Object.freeze()` works just fine on arrays.
- resonantjacket5 6y agoNice. Though I don't think that solves the rest of the issues I outlined sadly. I guess you could have this json+ convert into some custom javascript class that allows arrays/objects as map keys rather than the normal javascript object that only accepts strings as map keys.
- chrisseaton 6y ago> I guess you could have this json+ convert into some custom javascript class that allows arrays/objects as map keys rather than the normal javascript object that only accepts strings as map keys. Sure - why not? JSON doesn't have to map directly to JavaScript objects.