---
title: "formatJson"
description: "Tiny wrapper around `JSON.stringify` with sensible default indentation."
package: "@maz-ui/utils"
url: "https://maz-ui.com/ecosystem/utils/format-json"
---

# formatJson

> Tiny wrapper around `JSON.stringify` with sensible default indentation.

- Package: `@maz-ui/utils`
- Import: `import { formatJson } from '@maz-ui/utils/helpers/formatJson'`
- Web: https://maz-ui.com/ecosystem/utils/format-json

## Usage

```ts
import { formatJson } from '@maz-ui/utils'

formatJson({ name: 'Alice', age: 30 })
// {
//   "name": "Alice",
//   "age": 30
// }

formatJson({ a: 1 }, 4) // → indent with 4 spaces
```

## API

```ts
function formatJson(json: unknown, indent?: number): string
```

| Parameter | Type      | Default | Description                              |
| --------- | --------- | ------- | ---------------------------------------- |
| `json`    | `unknown` | - | Any JSON-serialisable value              |
| `indent`  | `number`  | `2`     | Number of spaces per indentation level   |
