JSON Formatter
Ready
Input
Output
Formatted JSON will appear here

What is this JSON Formatter?

This is a free, real-time JSON formatter and validator that runs 100% in your browser. No data is sent to any server. It supports formatting (beautifying), minifying, sorting keys alphabetically, and real-time validation with line-accurate error messages.

How does JSON formatting work?

JSON.parse() converts your text into an in-memory JavaScript object, then JSON.stringify() renders it back with proper indentation. This also validates the JSON as a side effect " any syntax errors are caught and displayed with the exact character position.

Is my data safe?

All processing is done entirely in your browser's memory using JavaScript. No data is sent to any server. When you close this tab, the data is gone. This makes it safe to use with API keys, tokens, or private configuration files.

What does "Sort Keys" do?

It recursively sorts all object keys alphabetically throughout the entire JSON structure. Useful for comparing two JSON objects for differences or enforcing consistent key ordering in config files.

What is JSON minifying?

Minifying removes all whitespace, newlines, and indentation from valid JSON. The result is functionally identical but smaller " useful for reducing payload size in HTTP API responses or configuration files.

Copied! "

How to Use This Tool

Format MongoDB query results and BSON-like JSON documents with proper indentation for debugging and documentation.

  1. Copy your MongoDB query result from mongosh, MongoDB Compass, or your application logs.
  2. If the output uses MongoDB Extended JSON (e.g., {"$oid": "..."}), paste it directly — it is valid JSON.
  3. Click "Format" to display the documents with proper indentation and syntax highlighting.
  4. Use "Sort Keys" to alphabetize fields for consistent document structure across queries.
  5. Click "Copy" to grab formatted documents for documentation or issue reporting.

What Is MongoDB JSON Formatter?

MongoDB stores documents in BSON format, which extends JSON with types like ObjectId, Date, and Decimal128. When exported as Extended JSON, these types appear as objects with $ prefixes (e.g., {"$oid": "507f1f77bcf86cd799439011"}).

This tool formats MongoDB Extended JSON documents with proper indentation, making complex document structures with nested subdocuments and arrays readable and navigable.

All processing is client-side — safe for formatting documents containing user records, API keys, or sensitive business data from your MongoDB collections.

Why You Need This

Essential for MongoDB developers:

Pro Tips for Best Results

Frequently Asked Questions

Can this tool handle MongoDB Extended JSON types?

Yes. MongoDB Extended JSON ({"$oid": "..."}, {"$date": "..."}, {"$numberDecimal": "..."}) is valid standard JSON and formats perfectly in this tool. The $ prefixed keys are just regular JSON keys.

How do I format BSON directly?

BSON is a binary format that cannot be pasted as text. First export your data as Extended JSON using mongoexport --jsonFormat=canonical or Compass's export feature, then paste the JSON here.

Why do MongoDB documents have _id fields?

MongoDB automatically generates an _id (ObjectId) for every document as a unique identifier. It appears as {"$oid": "..."} in Extended JSON format and contains an embedded creation timestamp.