All specs
Display · json-viewer

JSON Viewer

Syntax-highlighted formatted JSON display.

Anatomy

{
  "name": "caret",
  "version": 1,
  "private": true,
  "tags": [
    "cli",
    "ui"
  ]
}

Usage

jsonViewer({
  data: {
    name: 'caret',
    version: 1,
    private: true,
    tags: ['cli', 'ui'],
  },
})

// Also works with arrays, primitives, nested objects
jsonViewer({ data: [1, 2, 3] })
jsonViewer({ data: 'hello' })

Options

KeyTypeDefaultDescription
dataunknownAny JSON-serializable value
indentnumber?2Indentation width per level
maxDepthnumber?10Collapse to inline beyond this
maxStringLengthnumber?80Truncate long strings

Color mapping

TypeStyle
KeyAccent
StringDefault
NumberBold
BooleanSuccess (true) / Danger (false)
NullDim
EmptyDim ({}, [])
OverflowDim ({…3 keys})

Do & don't

Do — use for debugging, API response display, config inspection

Don't — use for structured data display (use keyValue or table)

Out of scope

Interactive collapse/expand (static output only)

JSON editing

JSON diffing (use diff)

Syntax highlighting for non-JSON