Skip to content

aduquehd/json-formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

190 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎨 JSON Viewer

A modern, privacy-first web app to format, validate, explore, and compare JSON β€” with a VS Code-style editor and rich visualizations

Live Demo

Next.js 15 React 19 TypeScript Tailwind CSS pnpm


✨ Features

Editing & Formatting

  • πŸ“ CodeMirror 6 Editor: VS Code-style editing with syntax highlighting, line numbers, and code folding
  • 🎯 JSON Formatting: Format with 2 spaces, 4 spaces, or tabs β€” plus optional Aβ†’Z key sorting
  • βœ… Real-time Validation: Live validation with inline error highlighting and a status bar (nodes, depth, lines, size)
  • πŸ”§ JSON Auto-fix: Automatic correction of common errors β€” trailing commas, single quotes, unquoted keys, missing commas
  • 🏷️ JavaScript Object Literal Support: Parse and format JS object literal syntax
  • πŸ“‹ Clipboard & Files: Copy, paste, open/drag-in .json files, and download the result

Visualization & Analysis

  • 🌳 Tree View: Interactive collapsible tree with inline editing of keys and values
  • πŸ“Š Graph View: Explore JSON as an interactive node-link graph (D3.js) with pan, zoom, and expand/collapse
  • πŸ”€ Compare / Diff: Side-by-side compare with split, unified, and semantic modes, "ignore key order", collapse-unchanged, and hunk navigation
  • πŸ“ˆ Statistics View: Key counts, nesting depth, and a full data-type breakdown
  • πŸ” Search & Filter: Find keys and values across large documents
  • πŸ—ΊοΈ Map View (beta): Plot latitude/longitude data on an interactive Leaflet map

App & Platform

  • 🌐 Internationalization: UI translated into 12 languages (English, Spanish, Hindi, Turkish, Dutch, Malay, Chinese, Tamil, and more)
  • 🎨 Theme Support: Light and dark themes with system-preference detection
  • πŸ”— A Real URL per View: /, /tree, /graph, /stats, /diff, /search, /map β€” reloadable, shareable, and indexable, while the workbench keeps your JSON when switching views
  • πŸ“š Guides & Help: Built-in JSON guides (syntax, common errors, JSON vs XML, JSON.parse, and more) at /guides and a help page at /help
  • πŸ“± Responsive UI: Works on desktop and mobile
  • πŸ”’ 100% Local Processing: Everything runs in your browser β€” no JSON is ever sent to a server

πŸ“Έ Screenshots

Taken with the built-in "Try an example JSON" β†’ Financial Sales dataset.

Editor

The main editor with formatting toolbar, validation status bar, and the Compare panel ready to open.

Editor view

Compare / Diff

Two documents compared side by side β€” changed lines highlighted, with split/unified/semantic modes and hunk navigation.

Diff view comparing two JSON documents

Tree View

Collapsible tree with inline editing β€” click any key or value to edit it directly.

Tree view

Graph View

JSON as an interactive node-link graph β€” click nodes to expand/collapse, scroll to zoom, drag to pan.

Graph view

πŸ“‹ Requirements

  • πŸ“¦ Node.js 18.18 or later (20+ recommended)
  • πŸš€ pnpm (primary package manager)

πŸš€ Quick Start

  1. Clone the repository:

    git clone https://github.com/aduquehd/json-viewer.git
    cd json-viewer
  2. Install dependencies:

    pnpm install

    (This also copies self-hosted editor assets and installs the Lefthook git hooks.)

  3. Run the development server (Turbopack):

    pnpm dev
  4. Open your browser and go to http://localhost:3000

πŸ’» Development

πŸ› οΈ Available Scripts

pnpm dev         # Development server with Turbopack
pnpm build       # Production build
pnpm start       # Start production server

pnpm format      # Format code (Biome)
pnpm fix         # Auto-fix formatting + safe lint issues + organize imports (Biome)
pnpm lint        # Lint Next.js framework rules (ESLint)
pnpm lint:biome  # General JS/TS linting (Biome)
pnpm typecheck   # Type-check the whole project (tsc --noEmit)
pnpm check       # Run every validation at once (Biome + ESLint + tsc)

🎨 Code Quality

The repo uses a hybrid lint/format setup:

  • Biome owns formatting, general JS/TS linting, and import organization (single quotes, 2-space indent, 100 print width)
  • ESLint (flat config) runs only the Next.js layer: next/core-web-vitals (React Hooks, next/image, jsx-a11y)
  • TypeScript strict mode with tsc --noEmit for type safety

πŸͺ Git Hooks (Lefthook)

A pre-commit hook (installed automatically on pnpm install) runs, in order:

  1. Biome β€” formats/lints/organizes imports on staged files (auto-fixes and re-stages)
  2. ESLint β€” checks staged JS/TS files against the Next.js rules
  3. tsc --noEmit β€” type-checks the project when a TS file is staged

Bypass once with git commit --no-verify if needed.

πŸ“‚ Project Structure

json-viewer/
β”œβ”€β”€ πŸ“ docs/
β”‚   └── πŸ“ screenshots/            # README screenshots
β”œβ”€β”€ πŸ“ public/                     # Static assets (manifest, robots.txt, images, self-hosted editor assets)
β”œβ”€β”€ πŸ“ scripts/
β”‚   └── πŸ“„ copy-monaco.mjs         # Copies editor assets into public/ (no CDN egress)
β”œβ”€β”€ πŸ“ src/
β”‚   β”œβ”€β”€ πŸ“ app/                    # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ πŸ“ (app)/              # Workbench views β€” one URL per view
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“„ page.tsx        #   /        Editor / formatter
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“„ tree/           #   /tree    Tree view
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“„ graph/          #   /graph   Graph view
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“„ stats/          #   /stats   Statistics
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“„ diff/           #   /diff    Compare / diff
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“„ search/         #   /search  Search & filter
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“„ map/            #   /map     Map view
β”‚   β”‚   β”‚   └── πŸ“„ layout.tsx      #   Shared shell β€” keeps editor state across views
β”‚   β”‚   β”œβ”€β”€ πŸ“ api/sitemap/        # Dynamic sitemap (rewritten from /sitemap.xml)
β”‚   β”‚   β”œβ”€β”€ πŸ“ guides/             # JSON guides (what is JSON, syntax, errors, JSON vs XML, …)
β”‚   β”‚   β”œβ”€β”€ πŸ“ help/               # Help & documentation page
β”‚   β”‚   β”œβ”€β”€ 🎨 globals.css         # Global styles and CSS theme variables
β”‚   β”‚   └── πŸ“„ layout.tsx          # Root layout with metadata
β”‚   β”œβ”€β”€ πŸ“ components/             # React components
β”‚   β”‚   β”œβ”€β”€ πŸ“ CodeMirrorEditor.tsx    # CodeMirror 6 integration
β”‚   β”‚   β”œβ”€β”€ πŸ–₯️ EditorWorkspace.tsx     # Editor layout + Compare call-to-action
β”‚   β”‚   β”œβ”€β”€ πŸ”€ CompareWorkspace.tsx    # Diff: split / unified / semantic modes
β”‚   β”‚   β”œβ”€β”€ 🧰 JsonWorkbench.tsx       # Central state manager for all views
β”‚   β”‚   β”œβ”€β”€ 🌳 TreeView.tsx            # Interactive JSON tree
β”‚   β”‚   β”œβ”€β”€ πŸ“Š GraphView.tsx           # D3.js node-link visualization
β”‚   β”‚   β”œβ”€β”€ πŸ“ˆ StatsView.tsx           # JSON statistics analysis
β”‚   β”‚   β”œβ”€β”€ πŸ” SearchView.tsx          # Search & filter
β”‚   β”‚   β”œβ”€β”€ πŸ—ΊοΈ MapView.tsx             # Leaflet geographic visualization
β”‚   β”‚   β”œβ”€β”€ πŸŽ›οΈ ControlButtons.tsx      # Format / Compact / Copy / Open / Download controls
β”‚   β”‚   β”œβ”€β”€ πŸ“‘ TabsContainer.tsx       # View tabs (synced with the URL)
β”‚   β”‚   β”œβ”€β”€ πŸ“Ÿ StatusBar.tsx           # Validity, node count, depth, size
β”‚   β”‚   β”œβ”€β”€ 🌐 LanguageSelector.tsx    # 12-language switcher
β”‚   β”‚   β”œβ”€β”€ πŸŒ“ ThemeProvider.tsx       # Theme management
β”‚   β”‚   β”œβ”€β”€ πŸ“š JsonExampleModal.tsx    # Sample JSON picker
β”‚   β”‚   └── πŸ“ seo/                    # Per-view SEO content (FAQs, HowTo, JSON-LD)
β”‚   β”œβ”€β”€ πŸ“ hooks/                  # useTheme, useNotification
β”‚   β”œβ”€β”€ πŸ“ lib/                    # i18n setup, per-view SEO/routing metadata, gtag
β”‚   β”œβ”€β”€ πŸ“ locales/                # Translations (12 languages)
β”‚   β”œβ”€β”€ πŸ“ types/                  # Global TypeScript declarations
β”‚   └── πŸ“ utils/                  # jsonFixer, jsonUtils, jsonDiff, exampleData
β”œβ”€β”€ βš™οΈ biome.json                  # Biome formatter/linter config
β”œβ”€β”€ βš™οΈ eslint.config.mjs           # ESLint flat config (Next.js rules only)
β”œβ”€β”€ πŸͺ lefthook.yml                # Pre-commit hooks
β”œβ”€β”€ πŸš€ next.config.js              # Security headers, redirects, sitemap rewrite
β”œβ”€β”€ 🎨 tailwind.config.js          # Tailwind CSS configuration
└── βš™οΈ tsconfig.json               # TypeScript configuration (strict, @/* alias)

πŸ› οΈ Technology Stack

Framework

Next.js React TypeScript

Next.js 15 (App Router, Turbopack dev server), React 19, TypeScript in strict mode.

Styling & UI

Tailwind CSS Framer Motion

Tailwind CSS with CSS custom properties for theming, Framer Motion animations, Lucide icons, Notyf toasts.

Editor & Visualizations

CodeMirror D3.js Leaflet

CodeMirror 6 for the JSON editors, D3.js for the force-directed graph, Leaflet + react-leaflet for maps.

Internationalization

i18next + react-i18next with browser language detection β€” 12 supported languages.

Development Tools

pnpm Biome ESLint Vercel

pnpm, Biome, ESLint 9 (flat config), Lefthook git hooks, deployed on Vercel.

πŸ›οΈ Architecture Highlights

  • One URL per view, one shared workbench: every view (/, /tree, /diff, …) is a real, indexable page, but they all share a single persistent workbench β€” your JSON and options survive switching views because the layout instance persists across navigations.
  • 100% client-side processing: parsing, formatting, fixing, diffing, and visualization all run in the browser. No JSON ever leaves your device.
  • Dynamic imports: heavy views (Graph, Compare, Stats, Map) are lazy-loaded so the initial page stays fast.
  • SEO built-in: per-view metadata, FAQs, HowTo steps and JSON-LD, a dynamic sitemap (/sitemap.xml β†’ /api/sitemap), and permanent redirects from legacy keyword URLs (e.g. /tools/json-formatter β†’ /).
  • Hardened headers: CSP, HSTS, X-Frame-Options: DENY, X-Content-Type-Options: nosniff, strict Referrer-Policy and Permissions-Policy configured in next.config.js.
  • Self-hosted assets: editor assets are copied into public/ at install/build time β€” no third-party CDN requests.

πŸ”§ Configuration

Theme Customization

Themes are defined in src/app/globals.css using CSS custom properties. The app follows the system preference and persists the user's choice to localStorage.

Analytics (Optional)

Google Analytics 4 is only loaded when NEXT_PUBLIC_GA_MEASUREMENT_ID is set; otherwise no analytics code ships.

πŸ“¦ Deployment

Vercel (Recommended)

Deploy to Vercel with one click:

Deploy with Vercel

Manual Deployment

  1. Build the application:

    pnpm build
  2. The build output will be in the .next/ directory

  3. Deploy using your preferred hosting service that supports Next.js

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License.


Made with ❀️ by aduquehd

🌐 Live Demo β€’ πŸ› Report Bug β€’ πŸš€ Request Feature

About

Resources

Stars

42 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors