Componenteditors0.93 KB gzipZero dependencies

Json Editor

JSON editor with live validation, error line and format button.

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add json-editor

Or install the full npm package:

npm install bigbullui

Usage

tsx3 lines
import { JsonEditor } from "@/components/ui/json-editor"; <JsonEditor />

Source code

json-editor.tsx + 1 helper

Zero third-party dependencies (2 local files shown in tabs below).

tsxjson-editor.tsx69 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils"; export interface JsonEditorProps extends React.HTMLAttributes<HTMLDivElement> {  value?: string;  defaultValue?: string;  onValueChange?: (value: string, valid: boolean) => void;  height?: string;} function format(src: string): string {  try { return JSON.stringify(JSON.parse(src), null, 2); } catch { return src; }} function validate(src: string): { valid: boolean; error?: string } {  if (src.trim() === "") return { valid: true };

Props

Interactive Prop Playground

Tweak parsed AST props below to generate ready-to-paste JSX.

tsx3 lines
import { JsonEditor } from "@/components/ui/json-editor"; <JsonEditor />
PropTypeDescription
valuestringControlled value.
defaultValuestringInitial value when uncontrolled.
onValueChange(value: string, valid: boolean) => voidCallback invoked on value change.
heightstringConfigures height. (Default: "200px")