Skip to content

formatJson ​

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

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
ParameterTypeDefaultDescription
jsonunknown—Any JSON-serialisable value
indentnumber2Number of spaces per indentation level