3 ms·
One of the uses is mapping values to objects instead of strings, so you don’t have to use ids: ob = {...} somemap[ob] = value // vs somemap[ob.id] = va
by wruza 6y ago
One of the uses is mapping values to objects instead of strings, so you don’t have to use ids:
ob = {...}
somemap[ob] = value
// vs
somemap[ob.id] = value
In languages which allow weak keys in such maps, a garbage collector may even reclaim whole key-value pairs once ob falls out of existence. But to my opinion, in json it is barely useful for a number of reasons. It is more programming technique than data transfer format, and these features (and reference loops) should be encoded at a higher level than json.