stringifyJson

Creates a JSON stringify transformation action.

const Action = v.stringifyJson<TInput, TConfig, TMessage>(config, message);

Generics

Parameters

  • config TConfig
  • message TMessage

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

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,
  })
);

The following APIs can be combined with stringifyJson.

Schemas

Methods

Utils

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of @EskiMojo14
  • GitHub profile picture of @fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of @antfu
  • GitHub profile picture of @Thanaen
  • GitHub profile picture of @osdiab
  • GitHub profile picture of @ruiaraujo012
  • GitHub profile picture of @hyunbinseo
  • GitHub profile picture of @F0rce
  • GitHub profile picture of @UniquePixels
  • GitHub profile picture of @jdgamble555
  • GitHub profile picture of @nickytonline
  • GitHub profile picture of @KubaJastrz
  • GitHub profile picture of @andrewmd5
  • GitHub profile picture of @caegdeveloper
  • GitHub profile picture of @dslatkin
  • GitHub profile picture of @BrianCurliss