Skip to content

Overview / parseJson

parseJson() ​

parseJson<T>(text, schema, addDefaults): Promise<TypeOf<T>>

Parses a JSON string using the specified Zod schema. It also cleans a few common issues with generated JSON strings.

Type Parameters ​

Type Parameter
T extends AnyZodObject

Parameters ​

ParameterTypeDefault valueDescription
textstringundefinedThe JSON string to parse.
schemaTundefinedThe Zod schema to use for parsing.
addDefaultsbooleanfalseWhether to add default values to the parsed object.

Returns ​

Promise<TypeOf<T>>

Throws ​

If the JSON string is invalid or does not match the schema.

Released under the GPL-3.0 License.