Features
- Strict and loose JSON parsing
- Pretty-print with 2-space indentation
- Minification for compact output
- JavaScript object literal generation
- Detailed error messages with parse hints
- Automatic trailing comma removal
- Single-quote to double-quote conversion
Use Cases
API Response Formatting
Format minified JSON from API responses for readability
Configuration Files
Validate and format JSON configuration files before deployment
Code Minification
Reduce JSON payload size for network transmission
JavaScript Migration
Convert loose JavaScript objects to valid JSON format
Actions
Default (Format)
Pretty-prints JSON with 2-space indentation:Minify
Removes all whitespace for compact output:JavaScript Object
Converts to JavaScript object literal syntax:Input Formats
Strict JSON
Standard JSON with double-quoted keys:Loose JSON
JavaScript-style syntax with unquoted keys and single quotes:The loose JSON parser automatically normalizes JavaScript object syntax to valid JSON.
Examples
- Format JSON
- Minify JSON
- Loose JSON Parsing
- JavaScript Object
Pretty-print minified JSON.Input:Output:
Loose JSON Parser
The tool includes a permissive parser that handles common JavaScript syntax:Supported Transformations
| Input Syntax | Normalization |
|---|---|
{name: "value"} | Unquoted keys → Quoted keys |
{'name': 'value'} | Single quotes → Double quotes |
{a: 1, b: 2,} | Trailing commas → Removed |
{a:1} | No spaces → Formatted |
Implementation
Fromlib/tools/engine.ts:36-59:
Error Handling
The tool provides clear error messages:- Unquoted keys: Use
{"key": "value"}not{key: value}in strict mode - Single quotes: Use double quotes for strings in strict mode
- Trailing commas: Remove commas before closing braces/brackets
- Comments: JSON does not support
//or/* */comments