How to Open and Format a JSON File
Open JSON files on Windows, Mac, or Linux, format them in a browser or terminal, and fix common validation errors with practical examples.
Open a JSON file without changing its data
On Windows, right-click the file and choose Open with, then select a text editor such as Notepad or Visual Studio Code. On macOS, use Open With and a plain-text editor. On Linux, open the file with your preferred text editor. You do not need to install a database or run the file as a program.
Work on a copy when the file belongs to an application. A configuration file may require exact property names, value types, or a particular character encoding. A file that parses successfully can still be rejected by the application if required fields are missing.
For a small file, copy the text into the linked formatter. Its input accepts pasted text rather than file uploads. Avoid copying credentials or customer records into online tools; a local editor is a better choice for confidential files.
Format JSON online in three steps
The example below describes a fictional order. Indentation makes the nested address easier to inspect, while numbers and booleans remain their original types.
- Paste the JSON text into the JSON Formatter.
- Choose an indentation size and click Format & validate.
- Inspect the result, then copy it or download formatted.json.
{
"orderId": "A-104",
"total": 24.5,
"paid": true,
"address": {
"city": "Boston",
"country": "US"
}
}Pretty-print a file with Python
If Python 3 is installed, its json.tool module can read a file and write an indented copy. Run the command from the directory containing your file. Use a different output filename so you retain the original. On Windows, the Python launcher is commonly named py; on macOS and Linux, it is commonly python3.
A parsing error includes a location to investigate. Look immediately before that location as well: a missing comma on the previous line can cause an error at the next property. Python’s default parser accepts some extensions, including NaN, so use a strict JSON validator when you need interoperable JSON.
# Windows
py -m json.tool input.json formatted.json
# macOS / Linux
python3 -m json.tool input.json formatted.jsonCommon reasons a JSON file will not validate
JSON uses double quotes around property names and strings. It does not support JavaScript comments, trailing commas, undefined, or single-quoted strings. Fix the structure at the source when possible rather than replacing every quote automatically; apostrophes can be legitimate data.
| Problem | Example | Correction |
|---|---|---|
| Single quotes | {'name': 'Sam'} | {"name": "Sam"} |
| Trailing comma | {"active": true,} | {"active": true} |
| Wrong boolean case | {"active": True} | {"active": true} |
| Missing quotes on a key | {name: "Sam"} | {"name": "Sam"} |
Large files, duplicate keys, and long IDs
Browser formatters parse the entire document in memory. For a large export, use a local streaming tool or inspect a small representative sample. JSON Lines files contain separate JSON values on separate lines and are not one ordinary JSON document.
JavaScript numbers cannot represent every integer above 9,007,199,254,740,991 exactly. Store identifiers such as long account numbers as strings before they reach a JavaScript parser. Duplicate property names can also disappear during parsing because parsers often keep only the last value. Keep the original file if either issue is possible.
Frequently asked questions
Can I open JSON in Excel?
Excel versions with a JSON import option can transform JSON into a table. Nested arrays and objects need an explicit expansion step. A text editor or formatter is more appropriate when you want to preserve the original structure.
Does formatting repair invalid JSON?
No. This formatter reports syntax errors. Correct the error and format again. Guessing missing values or silently removing content could change the meaning of the file.
References
Check the official documentation for command options and runtime-specific behavior.
Integrated Tools & Learning Resources
DevX Tool combines deep engineering tutorials with client-side interactive tooling so you can test code, verify outputs, and troubleshoot bugs right away.
Related tutorials and articles
HTTP Error Codes: 400, 401, 403, 404, 429 & 500
Find what common HTTP errors mean, what to check in an API response, and when a retry can help. Includes a status-code comparison and debugging steps.
Read article Developer fundamentalsJSON vs YAML vs TOML: Which Configuration Format Fits?
Compare JSON, YAML, and TOML using the same configuration example. Understand comments, indentation, data types, and safe conversion between formats.
Read article Web Standards & DebuggingFix Expected Double-Quoted Property Name in JSON
Diagnose and resolve 'Expected double-quoted property name in JSON' errors. Learn how ECMA-404 differs from Python dicts and JS objects with automated regex and AST fixes.
Read article AI & LLM ArchitectureFix Invalid JSON Schema Errors in Structured Outputs
Fix Structured Outputs schema errors: additionalProperties, required fields, and Pydantic or Zod definitions. Includes JSON Schema debugging examples.
Read article