# stringifyJson

> This document is the Markdown version of [valibot.dev/api/stringifyJson/](https://valibot.dev/api/stringifyJson/). For the complete documentation index, see [llms.txt](https://valibot.dev/llms.txt).

Creates a JSON stringify transformation action.

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

## Generics

- `TInput` `extends any`
- `TConfig` `extends StringifyJsonConfig | undefined`
- `TMessage` `extends ErrorMessage<StringifyJsonIssue<TInput>> | undefined`

## 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

- `Action` `StringifyJsonAction<TInput, TConfig, TMessage>`

## Examples

The following examples show how `stringifyJson` can be used.

### Stringify JSON

Stringify a JSON object.

```ts
const StringifiedObjectSchema = v.pipe(
  v.object({ key: v.string() }),
  v.stringifyJson()
);
```

### Stringify JSON with replacer

Stringify a JSON object with a replacer function.

```ts
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`](/api/any.md), [`array`](/api/array.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`picklist`](/api/picklist.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md)

### Methods

[`pipe`](/api/pipe.md)

### Utils

[`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md)
