﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head># parseJson

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

Creates a JSON parse transformation action.

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

## Generics

- `TInput` `extends string`
- `TConfig` `extends ParseJsonConfig | undefined`
- `TMessage` `extends ErrorMessage<ParseJsonIssue<TInput>> | undefined`

## Parameters

- `config` `TConfig`
- `message` `TMessage`

### Explanation

With `parseJson` you can parse a JSON string. If the input is not valid JSON, you can use `message` to customize the error message.

## Returns

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

## Examples

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

### Parse and validate JSON

Parse a JSON string and validate the result.

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

### Parse JSON with reviver

Parse a JSON string with a reviver function.

```ts
const StringifiedObjectSchema = v.pipe(
  v.string(),
  v.parseJson({
    reviver: (key, value) =>
      typeof value === 'string' ? value.toUpperCase() : value,
  }),
  v.object({ key: v.string() })
);
```

## Related

The following APIs can be combined with `parseJson`.

### Schemas

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