@structium/json - API documentation β
Functions β
deserialize() β
ts
function deserialize<Res>(input: string): Promise<Res>Deserialize a JSON string into an object or array.
Type Parameters β
| Type Parameter | Description |
|---|---|
Res extends unknown | The expected return type of the deserialized object/array |
Parameters β
| Parameter | Type | Description |
|---|---|---|
input | string | The JSON content string |
Returns β
Promise<Res>
- The deserialized JavaScript object or array
Throws β
- If the input string is not valid JSON
serialize() β
ts
function serialize<I>(input: I, options?: DeserializeOptions): Promise<string>Serialize an object or array into a JSON string.
Type Parameters β
| Type Parameter | Description |
|---|---|
I extends unknown | The type of the object or array to serialize |
Parameters β
| Parameter | Type | Description |
|---|---|---|
input | I | The object or array to serialize |
options? | DeserializeOptions | Options to pass to JSON.stringify |
Returns β
Promise<string>
- The serialized JSON string
Type Aliases β
DeserializeOptions β
ts
type DeserializeOptions: {
replacer: (key: string, value: Any) => Any;
space: number | string;
};Type declaration β
| Name | Type | Description |
|---|---|---|
replacer? | (key: string, value: Any) => Any | Replacer function |
space? | number | string | Default 2 |
