Test files › Structured data › malformed-trailing-comma.json

Malformed JSON with a trailing comma

JSON with a trailing comma before the closing brace - invalid per RFC 8259.

↓ Download malformed-trailing-comma.json
Filenamemalformed-trailing-comma.json
FormatJSON
Size24 bytes (24 bytes)
MIME typeapplication/json
SHA-256d66c56297d3e2d3c7854ff366bccce90d007c64d890f21388bf0fc266a4219b9
What this file catchesError handling on config load. The failure message should name the file and the line, not surface a bare "Unexpected token }".

Handle it in code

Each snippet below was run against this exact file with Python 3.14.4 and Node 24.15.0 when this page was built, and the output shown is what it printed.

Python

Report where the error is. A line and column turn "invalid file" into something a user can fix.

import json

try:
    with open("malformed-trailing-comma.json", encoding="utf-8") as f:
        json.load(f)
    print("valid")
except json.JSONDecodeError as e:
    print(f"invalid JSON at line {e.lineno}, column {e.colno}: {e.msg}")

Run against this file, it prints: invalid JSON at line 3, column 9: Illegal trailing comma before end of object

Node.js

The error message includes the position in recent Node versions.

const fs = require('node:fs');

try {
  JSON.parse(fs.readFileSync('malformed-trailing-comma.json', 'utf8'));
  console.log('valid');
} catch (e) {
  console.log('invalid JSON:', e.message);
}

Run against this file, it prints: invalid JSON: Expected double-quoted property name in JSON at position 22 (line 4 column 1)

Related guides and tools

Sample JSON fileJSONL and how it breaksCharacter encodingsVerify its SHA-256

Download & verify

curl -fsSL -o "malformed-trailing-comma.json" "https://files.hexaqa.com/json/malformed-trailing-comma.json"
curl -fsSL "https://files.hexaqa.com/json/malformed-trailing-comma.json" | sha256sum # expect: d66c56297d3e2d3c7854ff366bccce90d007c64d890f21388bf0fc266a4219b9

More structured data test files

ragged-rows.csvvalid-simple.csvdeeply-nested-100000.jsonlarge-array-100mb.jsonndjson-10000-lines.ndjsonprecision-loss.jsonvalid-small.jsonbillion-laughs.xml

← All Structured data files