Skip to content

idev-sig/json-format-converter

Repository files navigation

JSON Format Converter

Version License Chrome Extension

English | δΈ­ζ–‡

A powerful Chrome extension and standalone web application for converting between JSON, JSONC (JSON with Comments), and JSON5 formats with advanced editing features and comment preservation.

πŸš€ Quick Start

Chrome Extension

Chrome Web Store

Install from Chrome Web Store: JSON Format Converter

  1. Click the link above or visit the Chrome Web Store
  2. Click "Add to Chrome"
  3. Click the extension icon in your toolbar to start converting

Online Web App

Live Demo

Try Online: https://idev-sig.github.io/json-format-converter/

No installation required - use directly in your browser!

Features

🎨 Advanced Editor

  • Syntax Highlighting: CodeMirror editor with JSON syntax highlighting
  • Line Numbers: Easy navigation and debugging
  • Auto-completion: Smart bracket matching and auto-closing
  • Real-time Validation: Instant error detection and highlighting

πŸ”„ Smart Format Conversion

  • Bidirectional Conversion: JSON ↔ JSONC ↔ JSON5
  • Comment Preservation: Maintains comments when converting between JSONC and JSON5
  • Same-Format Processing: JSONC β†’ JSONC and JSON5 β†’ JSON5 preserve all comments and formatting
  • Intelligent Syntax Handling: Automatic property name quoting/unquoting
  • Real-time Conversion: Instant conversion as you type

πŸ› οΈ Processing Tools

  • Format & Prettify: Beautify and format JSON data
  • Compress/Minify: Remove all unnecessary whitespace
  • Escape/Unescape: Handle JSON string escaping for embedding
  • Data Type Conversion: Convert numbers ↔ strings

πŸ“Š Advanced Sorting

  • Sort object keys alphabetically (A-Z or Z-A)
  • Deep sorting for nested objects
  • Preserve or reorganize data structure

πŸ’Ύ File Operations

  • Copy to clipboard with one click
  • Download converted files
  • Support for multiple file formats

βš™οΈ Customizable Options

  • Configurable indentation (2 spaces, 4 spaces, or tabs)
  • Multiple sorting options
  • Real-time preview of changes

🌐 Dual Mode

  • Chrome extension for quick access
  • Standalone web page for full-featured editing
  • Responsive design for desktop and mobile

⌨️ Productivity Features

  • Keyboard shortcuts for common actions
  • Auto-conversion on input change
  • Comprehensive help documentation

🌍 Multi-language Support

  • English (Default), Chinese (δΈ­ζ–‡), Japanese (ζ—₯本θͺž), Korean (ν•œκ΅­μ–΄), German (Deutsch), French (FranΓ§ais), Spanish (EspaΓ±ol), Russian (Русский), Arabic (Ψ§Ω„ΨΉΨ±Ψ¨ΩŠΨ©), Portuguese (PortuguΓͺs) interface
  • Automatic Language Detection: Detects browser language preference
  • Persistent Settings: Language choice saved in localStorage
  • Localized Content: Sample data, help text, and error messages
  • Real-time Switching: Change language without page reload
  • Help Documentation: Multi-language help and keyboard shortcuts

πŸ’¬ Comment Preservation

  • JSONC ↔ JSON5: Preserves all comments during conversion
  • Same Format: JSONC β†’ JSONC and JSON5 β†’ JSON5 maintain formatting
  • Smart Processing: Removes comments only when converting to standard JSON
  • Multiple Comment Types: Supports // single-line and /* */ multi-line comments

Supported Formats

JSON (JavaScript Object Notation)

Standard JSON format with strict syntax rules.

JSONC (JSON with Comments)

JSON format that supports:

  • Single-line comments (//)
  • Multi-line comments (/* */)
  • Trailing commas

JSON5 (JSON for Humans)

Extended JSON format that supports:

  • Comments (single and multi-line)
  • Trailing commas
  • Unquoted property names
  • Single-quoted strings
  • Multi-line strings
  • Additional number formats

Installation

πŸ“¦ Pre-built Packages

Download the latest release from GitHub Releases:

Chrome Extension

  1. Download json-format-converter-chrome.zip
  2. Extract the ZIP file
  3. Open Chrome and navigate to chrome://extensions/
  4. Enable "Developer mode" in the top right
  5. Click "Load unpacked" and select the extracted folder
  6. The extension will appear in your toolbar

Standalone Web App

  1. Download json-format-converter-standalone.zip
  2. Extract the ZIP file to your web server
  3. Open index.html in any modern web browser
  4. Or deploy the files to any web hosting service

πŸ› οΈ Build from Source

# Clone the repository
git clone https://github.com/idev-sig/json-format-converter.git
cd json-format-converter

# Build all targets (Chrome, Firefox, Standalone)
npm run build

# Or build specific targets
npm run build:chrome      # Chrome extension only
npm run build:firefox     # Firefox extension only
npm run build:standalone  # Standalone web app only

# Files will be generated in dist/ directory
# - dist/chrome/ (Chrome extension)
# - dist/firefox/ (Firefox extension)
# - dist/standalone/ (Web app)
# - *.zip files (Distribution packages)

Usage

🎯 Quick Start

Chrome Extension

  1. Click the extension icon in your toolbar
  2. Paste your JSON, JSONC, or JSON5 data in the input panel
  3. Select the input and output formats from the dropdowns
  4. The conversion happens automatically in real-time
  5. Use the panel buttons for additional processing
  6. Copy or download the result from the output panel

Standalone Web App

  1. Open the web app in your browser
  2. Use the same interface with a wider, more comfortable layout
  3. Perfect for complex editing tasks and bookmarking
  4. Access comprehensive help documentation

πŸ”„ Conversion Examples

Comment Preservation

// JSONC β†’ JSON5 (preserves comments)
{
    // Configuration settings
    "name": "My App",
    "version": "1.0.0", // Current version
}

// Converts to:
{
    // Configuration settings
    name: "My App",
    version: "1.0.0", // Current version
}

Same Format Processing

// JSONC β†’ JSONC (preserves all comments and formatting)
// JSON5 β†’ JSON5 (preserves all comments and formatting)

πŸŽ›οΈ Button Functions

Input Panel

  • Clear: Remove all content from input editor
  • Format: Beautify and format the input JSON with proper indentation
  • Compress: Minify the input JSON (remove all whitespace)
  • Escape: Escape JSON string for safe embedding in code
  • Unescape: Remove escape characters from JSON string
  • Example: Load localized sample data for the current format

Output Panel

  • Copy: Copy formatted output to clipboard with success feedback
  • Download: Save output as .json file with automatic naming
  • Numβ†’Str: Convert all numeric values to string format
  • Strβ†’Num: Convert numeric strings back to number format

⌨️ Keyboard Shortcuts

  • Ctrl/Cmd + Enter: Format and beautify input
  • Ctrl/Cmd + Shift + C: Copy output to clipboard
  • Ctrl/Cmd + Shift + D: Download output as file
  • Escape: Clear all input and output
  • F1: Open help documentation with keyboard shortcuts

🎨 Visual Feedback

  • Button States: Active (green) β†’ Success (green) β†’ Normal state transitions
  • Real-time Validation: Instant error highlighting and syntax checking
  • Status Messages: Clear success/error notifications
  • Language Switching: Seamless interface language changes

Project Structure

json-format-converter/
β”œβ”€β”€ src/                    # Source code directory
β”‚   β”œβ”€β”€ manifest.json       # Chrome extension manifest
β”‚   β”œβ”€β”€ html/               # HTML files
β”‚   β”‚   β”œβ”€β”€ popup.html      # Extension popup interface
β”‚   β”‚   β”œβ”€β”€ standalone.html # Standalone web page
β”‚   β”‚   └── help.html       # Help documentation
β”‚   β”œβ”€β”€ css/                # Stylesheets
β”‚   β”‚   └── styles.css      # Main stylesheet
β”‚   β”œβ”€β”€ js/                 # JavaScript files
β”‚   β”‚   β”œβ”€β”€ i18n.js         # Internationalization
β”‚   β”‚   β”œβ”€β”€ converter.js    # Core conversion logic
β”‚   β”‚   └── popup.js        # UI interaction logic
β”‚   β”œβ”€β”€ lib/                # Third-party libraries
β”‚   β”‚   β”œβ”€β”€ codemirror.min.js
β”‚   β”‚   β”œβ”€β”€ javascript.min.js
β”‚   β”‚   └── json5.min.js
β”‚   └── icons/              # Extension icons
β”‚       β”œβ”€β”€ icon.svg        # Source icon
β”‚       β”œβ”€β”€ icon16.png      # 16x16 icon
β”‚       β”œβ”€β”€ icon32.png      # 32x32 icon
β”‚       β”œβ”€β”€ icon48.png      # 48x48 icon
β”‚       └── icon128.png     # 128x128 icon
β”œβ”€β”€ scripts/                # Node-based build and dev scripts
β”‚   β”œβ”€β”€ build.js            # Production builder (Chrome/Firefox/Standalone)
β”‚   β”œβ”€β”€ dev-server.js       # Lightweight dev server
β”‚   β”œβ”€β”€ clean.js            # Clean artifacts
β”‚   └── update-libs.js      # Update vendored libs (JSON5/CodeMirror)
β”œβ”€β”€ dist/                   # Build output directory
β”‚   β”œβ”€β”€ chrome/             # Chrome extension build
β”‚   β”œβ”€β”€ firefox/            # Firefox extension build
β”‚   └── standalone/         # Standalone web app build
β”œβ”€β”€ package.json           # Project metadata
β”œβ”€β”€ .gitignore            # Git ignore rules
└── README.md             # This file

Development

Prerequisites

  • Node.js 18+ and npm
  • Modern web browser
  • ImageMagick (only if you want to rebuild icons)

πŸš€ Quick Start

# Clone the repository
git clone https://github.com/idev-sig/json-format-converter.git
cd json-format-converter

# Start development server
npm run dev

# Build for production (Chrome + Firefox + Standalone)
npm run build

# Build a specific target
npm run build:chrome
npm run build:firefox
npm run build:standalone

# Update vendored libraries (JSON5/CodeMirror)
npm run update:libs

# Clean artifacts
npm run clean

πŸ”§ Development Workflow

  1. Edit Source: Modify files in the src/ directory
  2. Live Development: npm run dev then open http://localhost:8080/standalone.html
  3. Extension Testing: Build first, then load in chrome://extensions/ or about:debugging
  4. Package: Zip files are produced automatically in project root

πŸ“‹ Available Commands

# Development
npm run dev               # Start development server (default: 8080)

# Building
npm run build             # Build all targets
npm run build:chrome
npm run build:firefox
npm run build:standalone

# Utilities
npm run update:libs       # Update JSON5/CodeMirror from jsDelivr
npm run clean             # Remove dist and archives

🎨 Building Icons

If you need to regenerate icons from the SVG source:

# Requires ImageMagick
cd src/icons
convert icon.svg -resize 16x16 icon16.png
convert icon.svg -resize 32x32 icon32.png
convert icon.svg -resize 48x48 icon48.png
convert icon.svg -resize 128x128 icon128.png

πŸ› οΈ Technology Stack

Core Technologies

  • Vanilla JavaScript: No framework dependencies for maximum compatibility
  • CodeMirror 5: Advanced code editor with syntax highlighting
  • JSON5: Extended JSON parsing with comment support
  • CSS3: Modern styling with flexbox and grid layouts

Build System

  • Node.js: Cross-platform build system (Windows, Linux, macOS)
  • NPM Scripts: Standard package management and build commands

Browser APIs

  • Chrome/Firefox Extension APIs
  • Web APIs: Clipboard, File Download, LocalStorage
  • ES6+ Features: Modern JavaScript with broad browser support

πŸ“¦ Third-party Libraries & CDN

Update these assets using:

npm run update:libs
# or specify versions
node scripts/update-libs.js --json5 2.2.3 --cm 5.65.16

All third‑party files are vendored under src/lib/ for offline/packaged usage.

🌐 Browser Compatibility

  • Chrome Extension: Chrome 88+ (Manifest V3)
  • Standalone Web App: ES6+ modern browsers
    • Chrome 88+ βœ…
    • Firefox 128+ βœ…
    • Safari 14+ βœ…
    • Edge 88+ βœ…
    • Opera 74+ βœ…

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository on GitHub
  2. Clone your fork locally
  3. Create a feature branch: git checkout -b feature/amazing-feature
  4. Make your changes and test thoroughly
  5. Run validation: node scripts/validate.js
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Push to your branch: git push origin feature/amazing-feature
  8. Submit a pull request

πŸ“ Development Guidelines

  • Follow existing code style and conventions
  • Add tests for new features
  • Update documentation as needed
  • Ensure all validation checks pass
  • Test in both extension and standalone modes

πŸ“„ License

Apache 2.0 License - feel free to use this project for personal or commercial purposes.

See LICENSE file for details.

πŸ™ Acknowledgments

  • CodeMirror - Excellent code editor component
  • JSON5 - JSON for humans specification and parser

πŸ“ž Support


Β© 2025 JSON Format Converter.