Skip to content

LLM Resources

@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 ParameterDescription
Res extends unknownThe expected return type of the deserialized object/array

Parameters ​

ParameterTypeDescription
inputstringThe 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 ParameterDescription
I extends unknownThe type of the object or array to serialize

Parameters ​

ParameterTypeDescription
inputIThe object or array to serialize
options?DeserializeOptionsOptions 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 ​

NameTypeDescription
replacer?(key: string, value: Any) => AnyReplacer function
space?number | stringDefault 2