Skip to content

webshrine / stdtyp/src / SerializableToJSON

Interface: SerializableToJSON

Defines a type that can be serialised to a JSON string via the toJSON method or JSON.stringify(...) call

See

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior

Example

ts
class SomeObject implements SerializableToJSON {
  toJSON = () => '["SomeObject\'s data"]'
}

const str = JSON.stringify(new SomeObject()) // '["SomeObject's data"]'

#interface #atom #serialisation

Properties

toJSON()

toJSON: () => string

Returns

string

Defined in

packages/stdtyp/src/interfaces/index.ts:41