Data Transformation beginner 8 min

Find the JSON Syntax Error Breaking a Request

Validate JSON and locate the exact syntax issue before blaming the API.

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

  1. Open JSON Validator.
  2. 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.
  3. Run validation and read the reported location: the parser stops at the ] because the comma before it promises another array element that never comes.
  4. Delete the trailing comma after "admin" and re-validate the entire payload rather than assuming one fix is the only fix.
  5. 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