JSON (JavaScript Object Notation) is a text format for exchanging structured data. Formatting makes nested objects and arrays easier to read; validation checks whether the text follows JSON syntax. Valid JSON can still contain incorrect values or fail an application's requirements.
Basic JSON rules
- Use double quotation marks for keys and strings.
- Separate each key and value with a colon.
- Separate items with commas, but do not add a trailing comma.
- Valid values include strings, numbers, objects, arrays, true, false and null.
- Comments are not part of standard JSON.
Example
{
"name": "Asha",
"active": true,
"scores": [82, 91, 88],
"profile": {"city": "Indore", "verified": null}
}Common errors
- Using single quotes instead of double quotes.
- Missing a comma, colon, quote or closing bracket.
- Leaving a comma after the final item.
- Including comments or unsupported values.
Validation workflow
- Keep an unchanged copy of the source.
- Use a trusted formatter or validator.
- Fix syntax errors and format the JSON.
- Check required keys, data types and allowed values against the receiving application's schema.
- Test in a development or approved environment before production use.
Validity versus correctness
A validator can accept JSON that is unsuitable for a task. A required field may be missing or a value may be outside the permitted range. Syntax validation and business-rule validation are separate checks.
Privacy
JSON may contain API tokens, credentials, personal information or internal configuration. Do not submit sensitive payloads to an online service unless its privacy practices are appropriate. Prefer approved local tools for confidential data.
Final checklist
- JSON parses without syntax errors.
- Quotes, commas, colons, brackets and braces are balanced.
- Required fields and types meet the schema.
- Values are correct for the intended application.
- Secrets and personal data are not exposed.