JSON Validator: Check Syntax and Structure — Practical Guide
json validator: Validate JSON syntax first, then check required properties and data types against a schema or the receiving API contract. See how.

JSON validation has two layers: syntax validation confirms that a document follows JSON grammar, while schema validation checks whether its structure matches an expected contract. A file can pass the first and fail the second. Validate both before sending data to an API or loading configuration into an application. When a parser reports an error, use the line and column as a starting point, but inspect nearby delimiters because the actual mistake may occur just before the reported position.
Check JSON grammar
JSON uses double-quoted strings, commas between members, and matching braces and brackets. It does not allow comments, undefined, NaN, or trailing commas. Parse the entire document rather than only a fragment. If you have JSONC or JSON5, use a parser for that format and convert it to strict JSON before sending it to a system that expects RFC-compliant JSON.
Check the application schema
A JSON Schema can describe required fields, types, allowed values, array item shapes, and numeric bounds. Choose the correct schema draft and apply any formats your validator supports. A schema may still omit business rules such as whether a start date must be before an end date. Add those checks in the application. Validate examples from both successful and failing cases to confirm that the schema catches mistakes without rejecting valid data.
Use errors without exposing private data
A useful validation report identifies a path such as /items/2/price and explains the expectation. Avoid logging full request bodies if they contain credentials or personal information. Redact sensitive values while retaining enough context to reproduce the issue. Validation is not sanitization: accepted strings may still need escaping before insertion into HTML or SQL. Keep validation, authorization, and output encoding as separate controls.
Worked example
{"name":"Ada","age":"36"}
Syntax: valid JSON
Schema expectation: age is an integer
Structure result: invalid until age is 36 (number)Can valid JSON still be rejected by an API?
Yes. It may be syntactically valid but use missing fields, wrong types, unsupported values, or violate application rules.


