You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JSON does not (in and of itself) support circular references or multiple references to the same object.
I have some special handling to serialize references to other entities within the top level properties of entities, but this is not general, and it can be confusing that it works at the top level but not e.g. in an array.
There are numerous JavaScript libraries that intend to solve this problem, and many of them also extend the set of types that can be serialized to include undefined, RegExp, Date, etc.
Some of these libraries use JSON as the serial format, keeping keys, but replacing values with a special format.
This can be problematic for fields used for versioning the format, as a formatVersion: 5 may be serialized as formatVersion: 2 because the number 5 is the second (2) value that was serialized. To work around this, I could add such fields to the document after serialization, although most libraries probably do not provide a way to hook in so as to avoid having to reparse the JSON and restringify it. I could include the serialized data under a top level data field, which would either have the same inefficiency (reparsing and restringifying) or, if stored as a string, it would be inefficient on disk.
Here is a list of a bunch of serialization libraries I collected a while back:
sermat (you have to opt in to multiple reference support and circular reference support, but I guess I get what they're going for, they want you to have to think about it)
JSON does not (in and of itself) support circular references or multiple references to the same object.
I have some special handling to serialize references to other entities within the top level properties of entities, but this is not general, and it can be confusing that it works at the top level but not e.g. in an array.
There are numerous JavaScript libraries that intend to solve this problem, and many of them also extend the set of types that can be serialized to include
undefined
,RegExp
,Date
, etc.Some of these libraries use JSON as the serial format, keeping keys, but replacing values with a special format.
This can be problematic for fields used for versioning the format, as a
formatVersion: 5
may be serialized asformatVersion: 2
because the number5
is the second (2
) value that was serialized. To work around this, I could add such fields to the document after serialization, although most libraries probably do not provide a way to hook in so as to avoid having to reparse the JSON and restringify it. I could include the serialized data under a top leveldata
field, which would either have the same inefficiency (reparsing and restringifying) or, if stored as a string, it would be inefficient on disk.Here is a list of a bunch of serialization libraries I collected a while back:
extend Serializable
? hm...)The text was updated successfully, but these errors were encountered: