JSON Example: Valid Documents, Error Messages and JSON Schema
JSON examples you can copy: a valid document, every value type, real parser error messages, an API error response, a JSON Schema, and how to validate and format.
Have broken JSON right now? Fix it free in under 1 second — no signup.
Fix My JSON →A JSON example is a text document built from the RFC 8259 value types: object, array, string, number, true, false and null. Objects use curly braces with double-quoted string keys, and values are separated by commas. This page gives a valid sample, real error messages from JavaScript and Python, an API error response, and a JSON Schema example.
Written by The JSON Medic.
A basic valid JSON example
{
"name": "Ada Lovelace",
"age": 36,
"active": true
}
{ }— an object: a set of name/value pairs."name"— a key. Keys are always strings in double quotes.:— separates a key from its value.,— separates the pairs. There is no comma after the last one."Ada Lovelace",36,true— the values: a string, a number and a boolean.
Paste it into the JSON validator and it reports Valid JSON.
Every JSON value type with an example
{
"object": { "city": "London" },
"array": [1, 2, 3],
"string": "text in double quotes",
"number": -12.5e3,
"true": true,
"false": false,
"null": null
}
Numbers follow a strict grammar in RFC 8259: an optional minus sign, then digits with no leading zero (7, not 07), an optional fraction and an optional exponent. NaN, Infinity, hex such as 0x1F, and a trailing decimal point such as 1. are not JSON numbers. A JSON text does not have to be an object: "hello", 42 and null are valid JSON documents on their own.
JSON error message examples
The same mistake produces different messages in different parsers. These were run on Node.js 24 (JSON.parse) and Python 3.12 (json.loads):
| Broken JSON | JavaScript (Node.js 24) | Python 3.12 |
|---|---|---|
{"a": 1,} trailing comma | Expected double-quoted property name in JSON at position 8 (line 1 column 9) | Expecting property name enclosed in double quotes: line 1 column 9 (char 8) |
{'a': 1} single quotes | Expected property name or '}' in JSON at position 1 (line 1 column 2) | Expecting property name enclosed in double quotes: line 1 column 2 (char 1) |
{a: 1} unquoted key | Expected property name or '}' in JSON at position 1 (line 1 column 2) | Expecting property name enclosed in double quotes: line 1 column 2 (char 1) |
{"a": 1 // note + line break + } comment | Expected ',' or '}' after property value in JSON at position 8 (line 1 column 9) | Expecting ',' delimiter: line 1 column 9 (char 8) |
{"a": [1, 2 cut off | Expected ',' or ']' after array element in JSON at position 11 (line 1 column 12) | Expecting ',' delimiter: line 1 column 12 (char 11) |
Note that neither message says "trailing comma" or "comment": a parser reports the character it did not expect, not the cause. Messages also change between engine versions, so match on the position, not the wording. The guides under JSON errors take each message by language.
JSON error response example
APIs usually answer a failed request with a JSON body that describes the error. RFC 8259 says nothing about its shape; each API picks its own. One standard shape is RFC 9457, "Problem Details for HTTP APIs", served with the media type application/problem+json:
{
"type": "https://example.com/probs/out-of-credit",
"title": "You do not have enough credit.",
"status": 403,
"detail": "Your current balance is 30, but that costs 50.",
"instance": "/account/12345/msgs/abc"
}
type, title, status, detail and instance are the members RFC 9457 defines; an API may add its own. A common home-grown shape looks like this:
{
"error": {
"code": "invalid_request",
"message": "The field 'email' is required.",
"details": [{ "field": "email", "issue": "missing" }]
}
}
Both are ordinary, valid JSON. If an API returns something that will not parse, see API integration.
JSON validator example
Paste this into the JSON validator:
{
"name": "Ada",
"tags": ["math", "code",]
}
It reports Invalid JSON, then Line 3, column 27, the message Trailing comma — remove the comma before the closing ]., and the line with a caret under the bracket. Validation here is a syntax check only: valid JSON can still have the wrong fields for your program. Checking fields and types is what a JSON Schema does (below).
JSON formatter example (before and after)
Before, minified:
{"id":7,"name":"Ada","tags":["math","code"],"address":{"city":"London"}}
After the JSON formatter with its default of 2 spaces:
{
"id": 7,
"name": "Ada",
"tags": [
"math",
"code"
],
"address": {
"city": "London"
}
}
The formatter also offers 4 spaces and sorting keys A–Z. Minify goes back the other way.
JSON formatter JavaScript example
const data = JSON.parse('{"name":"Ada","tags":["a"]}');
JSON.stringify(data, null, 2); // indent with 2 spaces
JSON.stringify(data, null, '\t'); // indent with tabs
JSON.stringify(data); // minified, one line
The third argument, space, is a number of spaces or a string to indent with. The ECMAScript standard caps it at 10: a number above 10 is treated as 10, and only the first 10 characters of a string are used. JSON.parse throws a SyntaxError on invalid input, so wrap it in try/catch when the text comes from outside your program.
What is JSON Schema, with an example
JSON Schema is a separate specification for describing what a JSON document should contain: which fields, which types, which values. It is not part of RFC 8259, which only defines syntax. A schema is itself a JSON document:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer", "minimum": 0 },
"role": { "enum": ["admin", "editor", "viewer"] },
"tags": { "type": "array", "items": { "type": "string" } }
},
"required": ["name", "age"]
}
This instance is valid against it:
{ "name": "Ada", "age": 36, "role": "admin", "tags": ["math"] }
This one is valid JSON but fails the schema. A draft 2020-12 validator (we used Ajv 8) reports /age must be >= 0 and /role must be equal to one of the allowed values:
{ "name": "Ada", "age": -1, "role": "owner" }
To start a schema from a sample instead of writing it by hand, paste the sample into the JSON Schema generator; it writes a draft 2020-12 schema with type, properties, required and items, which you then tighten with keywords such as minimum and enum.
JSON Schema keywords at a glance
| Keyword | Meaning | Example |
|---|---|---|
type | The allowed JSON type | {"type": "string"} |
properties | Schemas for named object members | {"properties": {"age": {"type": "integer"}}} |
required | Members that must be present | {"required": ["name"]} |
items | Schema for every array element | {"items": {"type": "string"}} |
enum | The value must be one of a list | {"enum": ["admin", "editor"]} |
minimum | Lowest allowed number | {"minimum": 0} |
Fix a broken example
If your example will not parse, paste it into the JSON repair tool. It removes trailing commas, converts single quotes, quotes bare keys, removes comments and closes cut-off arrays and objects, and lists each change. Try it on the broken validator example above:
More basics are in Learn JSON and the glossary; conversions to CSV, YAML and more are under Convert.
FAQ
What is a simple JSON example?
An object such as {"name": "Ada", "age": 36, "active": true}. Keys are double-quoted strings, values follow a colon, and members are separated by commas, as RFC 8259 defines.
What does a JSON error example look like?
A trailing comma, as in {"a": 1,}, is invalid under RFC 8259. Parsers reject it: Node.js 24 says "Expected double-quoted property name in JSON at position 8 (line 1 column 9)". The wording depends on the parser and its version.
Does JSON allow comments or single quotes?
No. RFC 8259 allows only double-quoted strings and defines no comment syntax. Documents using either are invalid JSON.
Is JSON Schema part of the JSON standard?
No. RFC 8259 defines JSON syntax only. JSON Schema is a separate specification that describes the structure of JSON documents.
How can I check my JSON for errors?
Paste it into the JSON validator on this site. It reports the first error with its line and column, and it is free with no signup.
Still dealing with broken JSON?
Paste it in and get it fixed in under 1 second — free, no signup, no install. Works with ChatGPT, Claude, n8n, and any AI output.
Fix My JSON Free →The JSON Medic newsletter
One JSON error and its fix, weekly, plus new guides and tools. Free.
We send a confirmation link first. Unsubscribe with one click in any mail. See the privacy policy.
Related Articles