What is superjson?
Superjson is a flexible and powerful library for serializing JavaScript data structures, including those that are not supported by JSON, such as Dates, RegExps, Maps, Sets, and more. It allows for seamless serialization and deserialization of complex data types, making it easier to work with complex data in applications that require data persistence or transmission.
Serialization of complex types
Superjson can serialize complex JavaScript types like Dates, Maps, and Sets into a string representation that can be easily transmitted or stored. Upon deserialization, these strings are converted back into their original complex types.
{"date": "2023-04-14T12:00:00.000Z", "map": "[[\"key1\",\"value1\"],[\"key2\",\"value2\"]]", "set": "[\"a\",\"b\",\"c\"]"}
Custom serialization
Developers can define custom serialization and deserialization logic for unsupported types or to override the default behavior for supported types. This feature enhances flexibility and control over how data is serialized.
{"customType": "SerializedValue"}