stringifyJson
Creates a JSON stringify transformation action.
const Action = v.stringifyJson<TInput, TConfig, TMessage>(config, message);
Generics
TInputextends anyTConfigextends StringifyJsonConfig | undefinedTMessageextends ErrorMessage<StringifyJsonIssue<TInput>> | undefined
Parameters
configTConfigmessageTMessage
Explanation
With stringifyJson you can stringify a JSON object. If the input is unable to be stringified, you can use message to customize the error message.
Returns
ActionStringifyJsonAction<TInput, TConfig, TMessage>
Examples
The following examples show how stringifyJson can be used.
Stringify JSON
Stringify a JSON object.
const StringifiedObjectSchema = v.pipe(
v.object({ key: v.string() }),
v.stringifyJson()
);
Stringify JSON with replacer
Stringify a JSON object with a replacer function.
const StringifiedObjectSchema = v.pipe(
v.object({ key: v.string() }),
v.stringifyJson({
replacer: (key, value) =>
typeof value === 'string' ? value.toUpperCase() : value,
})
);
Related
The following APIs can be combined with stringifyJson.
Schemas
any, array, boolean, custom, date, enum, exactOptional, instance, intersect, lazy, literal, looseObject, looseTuple, nonNullable, nonNullish, nonOptional, null, nullable, nullish, number, object, objectWithRest, picklist, record, strictObject, strictTuple, string, tuple, tupleWithRest, union, unknown, variant
Methods
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/stringifyJson/