An object that cannot automatically be serialized to JSON using the
JSON.stringify() method can define an instance method named
toJSON() that returns the JSON-type representation of the original object.
JSON.stringify() will then use
toJSON() to get the object to stringify, instead of the original object.
Performance.toJSON() are examples of this approach.
A JSON string serialized in this way can be deserialized back to the JSON-type representation object using
It is common to provide a converter method, such as
PublicKeyCredential.parseCreationOptionsFromJSON(), to convert the JSON-type representation back to the original object.