DevX Tool
Back to Tech Blog
Everyday Developer Tasks 3 min read DevX Tool Team

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.

JSON Windows macOS Python

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.

  1. Paste the JSON text into the JSON Formatter.
  2. Choose an indentation size and click Format & validate.
  3. Inspect the result, then copy it or download formatted.json.
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.

Terminal
# Windows
py -m json.tool input.json formatted.json

# macOS / Linux
python3 -m json.tool input.json formatted.json

Common 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.

Common reasons a JSON file will not validate
ProblemExampleCorrection
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.

Advertisement
Put Knowledge Into Practice

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