Home Guides Text Guides

Text Guides

How to Format and Validate JSON

Learn how to format and validate JSON, identify common syntax errors, and check structured data safely with practical examples.

In this guide Step-by-step explanations, practical examples and useful context to help you complete the task confidently.

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

  1. Keep an unchanged copy of the source.
  2. Use a trusted formatter or validator.
  3. Fix syntax errors and format the JSON.
  4. Check required keys, data types and allowed values against the receiving application's schema.
  5. 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.

You've reached the end

Use the related tools, FAQs and next guides below to continue from the topic you just learned.

Use the solution

Try the Tervilo Tools

Finish the task with a practical Tervilo tool related to this guide.

Questions & answers

Frequently Asked Questions

Does formatting JSON make invalid JSON valid?

No. Formatting changes presentation. Validation checks syntax, and an invalid document still needs its syntax corrected.

Why is valid JSON rejected by an API?

Valid syntax does not guarantee that the data matches the API's schema. Check required fields, property names and expected data types.

Can JSON use single quotes?

JSON strings and property names use double quotes. Single quotes are common in some programming languages but are not valid JSON string delimiters.

Should I paste API keys into an online JSON formatter?

Do not expose credentials unnecessarily. Remove keys, tokens and other secrets before using an online service.

Learn more

Related Articles

Understand the wider topic with an informative Tervilo article.