Scenario
A request body copied from a docs page keeps failing with 400 Bad Request, and the server log shows Unexpected token ']' in JSON at position 44. That error means the payload never survived JSON.parse — no validation logic, no business rule, just broken syntax. The usual culprit in hand-edited JSON is a trailing comma: legal in JavaScript object literals, illegal in strict JSON. Validate the raw text first; everything downstream is noise until it parses.
Broken input
{
"name": "Ada",
"roles": ["admin",]
}
Goal
Use JSON Validator to pin the exact character that breaks parsing. A validator that reports line and position turns "the request fails" into "delete this comma."
Tool sequence
- Open JSON Validator.
- Paste the body exactly as it is sent — including the whitespace and that suspicious comma — because the error position only means something against the unmodified text.
- Run validation and read the reported location: the parser stops at the
]because the comma before it promises another array element that never comes. - Delete the trailing comma after
"admin"and re-validate the entire payload rather than assuming one fix is the only fix. - Once the body parses, check it against the API's expected shape with JSON Schema Validator / Generator — valid syntax and a valid contract are different gates.
Checkpoint output
{
"name": "Ada",
"roles": ["admin"]
}
Validation passes once the trailing comma after "admin" is removed — that single character was the entire 400 error.
Common mistakes
- Debugging server-side validation while the payload still fails
JSON.parse— read the parse error before reading application logs. - Fixing the first visible typo but not re-validating the whole payload; hand-edited JSON often carries two errors.
- Confusing JavaScript object syntax with strict JSON — trailing commas, single quotes, and unquoted keys all parse in JS and fail as JSON.
- Pasting the payload from a rendered docs page, which can smuggle in typographic quotes that look identical to
".
Related tools and lessons
- JSON Formatter - Format, minify, and filter JSON by keys.
- JSON Schema Validator / Generator - Validate JSON with Draft 2020-12 or generate starter schemas.
- cURL to fetch / Axios - Convert curl commands into fetch or axios code.
- Related lesson: Make a Nested JSON Response Readable
- Related lesson: Validate a Payload Against the Shape You Expect