← All blog posts

JSON Formatter for students — with examples

WhiteUI · A plain-English guide to the JSON Formatter

School and college work often asks for data in JSON: a marks record for a class project, a weather report for a geography assignment, or a small user record for a programming exercise. The JSON Formatter formats those blocks in seconds, and the examples below use the same numbers your coursework will, so you can check your own results against them before you hand anything in.

At a glance

Average mark: 85 out of 10085 scored15 to full marks78 + 85 + 92 = 255, ÷ 3 = 85
The three marks 78, 85 and 92 add up to 255, and 255 divided by 3 is an average of 85 out of 100.

Example 1: a marks record

Take a marks record for one student: {"name": "Rahul", "marks": [78, 85, 92], "passed": true}. It is 56 characters as pasted, and it has three keys: name, marks and passed. In Pretty mode it becomes 80 characters across 9 lines, with the three marks sitting four spaces in, inside the list, and in Compact mode it becomes 49 characters on one line. The marks themselves are unchanged in both versions, and they add up to 255, which divided by 3 gives an average of 85. If the formatted output still shows 78, 85 and 92, the data survived formatting intact.

Example 2: a weather object

Try a weather report for a geography assignment: {"city": "Mumbai", "temp_c": 31, "rain": false}. It is 47 characters as pasted, with three keys: city, temp_c and rain. In Pretty mode it becomes 55 characters across 5 lines, one line per key plus the two braces, and in Compact mode it becomes 42 characters. The temperature, 31, and the rain value, false, are unchanged. Short flat objects like this one are the easiest to read in Pretty mode, because every value sits on its own line.

Example 3: a user record for a programming exercise

For a programming exercise, try a user record: {"id": 1042, "name": "Anita Sharma", "email": "[email protected]", "orders": 3}. It is 79 characters as pasted, with four keys. In Pretty mode it becomes 89 characters across 6 lines, and in Compact mode it becomes 72 characters. The id, 1042, and the order count, 3, are numbers, so they stand without quotes, while the name and the email are in double quotes, because they are text. That difference, numbers bare and text quoted, is one of the first things a teacher checks, and formatting makes it easy to see.

Counting lines and spaces for homework

The indent rule is a handy anchor for coursework: two spaces per level. In the marks record, the name and passed keys sit two spaces in, at the first level, and the three marks sit four spaces in, at the second level, because they are inside the list. In a deeper example, {"a": {"b": {"c": 1}}}, the value 1 sits six spaces in, at the third level. Write the anchor down, two spaces times the level, and most classroom questions about how a formatted block is laid out answer themselves.

What the error messages teach

The errors are worth reading, because they are the same errors a real program would report. {oops} fails at position 1, because the keys are not in double quotes. {"a": 1,} fails at position 8, because of the comma before the closing brace. A trailing comma inside a list, such as [78, 85, 92,], fails at the closing bracket. Each error names a position, and counting to that position is a skill in itself: the first character is at position 0, so position 1 is the second character, not the first.

The common mistake

Students sometimes write JSON the way they write Python, with single quotes around text, because Python accepts them. JSON does not: {"name": "Rahul"} written with ’ fails at position 1, the very first character. Use double quotes for every key and every piece of text, and the same input formats cleanly. The other classroom slip is a comma after the last mark, such as [78, 85, 92,], which fails at the closing bracket: remove that last comma and the list is valid.

Frequently asked questions

What is a good first JSON example for classwork?

A marks record: {"name": "Rahul", "marks": [78, 85, 92], "passed": true}, which is 56 characters in, 80 in Pretty across 9 lines, and 49 in Compact.

What is the average of 78, 85 and 92?

85. The three marks add up to 255, and 255 divided by 3 is 85.

How many spaces of indent is each level?

Two spaces per level: top-level keys sit 2 spaces in, values inside a list sit 4 spaces in, and values one level deeper sit 6 spaces in.

Why does my JSON fail when my Python code works?

Because Python accepts single quotes and JSON does not. Use double quotes for every key and every piece of text in JSON.

More guides on the JSON Formatter

Try it yourself

Try the JSON Formatter — free, in your browser.

Open the JSON Formatter