Tutorials
Format and check a JSON file before you submit programming homework
Pretty-print a JSON file, find out whether it parses at all, and learn the three silent changes a formatter can make to your data before an auto-grader sees it.
AllYouConvert · Updated November 10, 2026 · 3 min read

On this page
Auto-graders and unit tests usually load your data file with a strict JSON parser. If that parser fails, the test fails before your code even runs, and the error message often points at the test harness rather than at the comma you forgot. Checking the file yourself first takes under a minute.
What the JSON Formatter actually does
The JSON Formatter reads your file in the browser and passes it to the same standard parser JavaScript uses (JSON.parse). If the file parses, it writes it back out with two-space indentation and downloads it under the same file name. If it does not parse, you get the message "JSON tidak valid." ("invalid JSON") and nothing is downloaded. The file is not uploaded anywhere.
The formatter tells you whether the file is valid, not where the mistake is. It does not repair anything. If you get the invalid message, use the checklist below or open the file in a code editor that underlines the exact line.
Why a file that looks fine still fails
- Trailing commas: [1, 2, 3,] or a comma after the last property. JavaScript objects allow this; JSON does not.
- Single quotes: {'name': 'Ana'} must be {"name": "Ana"}. Keys need double quotes too.
- Comments: // and /* */ are not part of JSON. Many config files tolerate them, but a strict parser rejects them.
- Copied curly quotes: text pasted from a document can turn " into “ ”, which the parser does not recognise.
- Unquoted special values: NaN, Infinity and undefined are not valid JSON values. Use null or a number.
- Two top-level values: a file with one object per line (JSON Lines) is not a single JSON document.
Three things formatting can quietly change
Because the formatter parses the data and writes it back out, anything the parser cannot represent is changed without warning. For most homework files nothing changes, but these cases are worth knowing before you hand in a formatted file:
- Duplicate keys: if an object contains "id" twice, only the last value survives. The output has one "id". If your assignment is about detecting duplicates, keep the original file.
- Very large integers: numbers above 9,007,199,254,740,991 lose precision, so a 19-digit ID can come back with different final digits. Store long IDs as strings.
- Escapes become characters: "caf\u00e9" is written back as "café". The value is identical, but a byte-for-byte diff against a reference file will show a change.
A quick routine before submission
1Run the original through the formatter
If you get the invalid message, fix the file first. Look for the patterns in the list above, starting at the end of the file, where trailing commas usually are.
2Compare the formatted output
Open the downloaded file next to the original. Same number of records? Same IDs? If a key disappeared, you had a duplicate.
3Decide which file to submit
If the assignment checks exact bytes, submit your original once it parses. If it only loads the data, the formatted version is easier for a marker to read.
4Run your own test once
Load the final file with the same language the grader uses, for example json.load in Python or JSON.parse in Node, before uploading.
Syntax errors versus schema errors
A file can be perfectly valid JSON and still fail the assignment. If a test expects "age": 21 and your file has "age": "21", the parser is happy but the comparison fails because one is a number and the other is a string. The formatter only checks syntax. For structure, read the field list in the assignment brief or run the provided tests locally.
If the next step is a spreadsheet, for example a report built from an API export, JSON to CSV turns an array of objects into rows. It expects an array of objects or an array of rows. A single nested object will be rejected.
01Does the formatter fix my JSON?
No. It only formats JSON that already parses. Invalid files are rejected with a message, and nothing is downloaded.
02Can I choose tabs or four spaces?
Not at the moment. The output always uses two-space indentation, which most style guides and graders accept.
03Is my homework file uploaded?
No. The file is read and written in your browser tab.
Check your JSON file
Drop the file in. If it parses, you get a cleanly indented copy. If it does not, you know before the grader does.
Open JSON Formatter


