October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Format and Validate JSON Easily

Use Python’s json.tool or VS Code to format and check JSON syntax, then validate separately against a JSON Schema when your application has structural rules.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a quick local check, run python -m json.tool input.json: it parses a JSON file and prints readable, indented output if the document is valid. To check whether valid JSON also meets an application’s required structure, validate it separately against the relevant JSON Schema. Formatting, syntax validation, and schema validation answer different questions.

What formatting and validation check

JSON is a language-independent data interchange format, not JavaScript object-literal syntax. RFC 8259 defines its grammar and states that a parser must accept texts that conform to it. A syntax check therefore catches problems such as malformed strings, missing commas, or invalid values; it does not decide whether a value makes sense to a particular application. RFC 8259

  • Formatting changes how JSON is laid out so people can read it more easily.
  • Syntax validation checks whether the text follows JSON grammar.
  • Schema validation checks whether a parseable JSON value meets specified structural and value constraints.

A file can pass the syntax check and still fail its schema—for example, because a required property is absent or a value has the wrong type.

Format and check JSON with Python

Python 3.12.15 documents json.tool as a command-line interface for validating and pretty-printing JSON. Run it from a terminal in the directory containing the file:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

python -m json.tool input.json

If the input parses, the command writes formatted JSON to standard output. If it is malformed, it reports an error rather than producing formatted output. To save the formatted result, redirect standard output to a different file:

python -m json.tool input.json > formatted.json

Keeping the input and output paths separate avoids overwriting the source file while you check the result. The command can also read from standard input and write to an output file; consult the Python 3.12.15 json.tool documentation for its invocation details and options.

Choose output options deliberately

The CLI documents options for indentation, compact output, sorting object keys, and disabling ASCII escaping. Choose these to suit your workflow: compact output is less readable, while sorting keys changes their displayed order. Use JSON Lines mode only for a sequence of separate JSON values, one per line—not for an ordinary JSON document containing one value. The Python documentation describes these options and the JSON Lines mode.

Format JSON in Visual Studio Code

For interactive editing, open the JSON file in Visual Studio Code and run Format Document. The documented keyboard shortcut is Shift+Alt+F on Windows and Linux, or Shift+Option+F on macOS. Formatting improves indentation and layout; it is not a substitute for checking application-specific rules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

VS Code can also provide schema-based checking when the correct JSON Schema is associated with the document. Its bundled JSON support covers schema drafts 4 through 7, with limited support for drafts 2019-09 and 2020-12. You can configure schema mapping in settings or use supported associations. Check the Visual Studio Code JSON guide for the current configuration details and boundaries.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Validate against a JSON Schema when rules matter

Use a schema when you need to enforce expectations such as required properties, allowed value types, or other rules defined for the data. Supply or associate the schema with the JSON instance, then run validation using a schema-aware tool. Choose a validator that supports the draft used by the schema; an editor’s visible feedback depends on its schema association and implementation.

Schema validation is separate from parsing: first ensure the document is valid JSON, then check that it satisfies the expected schema. If the tool reports an error, use the reported location or schema path to find the offending value, correct it, and rerun the same check.

Do not assume the format keyword is enforced

A schema may use format for values such as dates or times, but validators are not universally required to treat that keyword as an assertion. The JSON Schema reference notes that implementations can ignore unrecognized formats, and Python’s jsonschema documentation explains that format checking is not automatically required. If a format rule is important, confirm that the validator supports it and that its format checker is enabled. JSON Schema: format

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a tool based on the data and the check

  • Use a local editor for convenient formatting and inline feedback while editing; verify that the intended schema is associated and supported.
  • Use Python’s standard-library CLI for a repeatable local syntax check and pretty-printing, including in scripts.
  • Use a schema-aware validator when the application imposes structure or value constraints beyond JSON grammar.
  • Use an online formatter cautiously: no specific service’s privacy practices are established here. For confidential data, prefer a local tool unless you have checked the service’s data-handling terms.

A practical sequence for reliable results

  1. Check syntax. Run python -m json.tool input.json or open the file in a JSON-aware editor. Resolve any parse error first.
  2. Format for reading. Use the CLI’s output or VS Code’s Format Document command.
  3. Check the expected structure. Associate or supply the applicable JSON Schema and run a schema-aware validation.
  4. Inspect the right error. A syntax error points to invalid JSON text; a schema error points to a mismatch with the expected data rules. Correct the reported issue and rerun the relevant check.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.