{
  "id": 12166437,
  "title": "Why search-and-replace is the wrong way to fix a trailing comma in JSON",
  "url": "https://urgent.news/2026/10/05/why-search-and-replace-is-the-wrong-way-to-fix-a-trailing-comma-in",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-05T14:22:29.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/operloom_197c3fe09b5ca1c5/why-search-and-replace-is-the-wrong-way-to-fix-a-trailing-comma-in-json-3np6"
  },
  "original_language": "en",
  "account": "The comma at the end of a JSON file can cause it to become unusable. For example, { name : ada , roles : [ admin , ops], } results in a Python json.decoder.JSONDecodeError or Node SyntaxError. JSON syntax does not allow trailing commas, so the parser stops at the first problem.\n\nThe one-liner fix, re.sub(r ',\\s*([}\\]]) , r '\\1', text), works for simple cases. However, it can corrupt values inside strings, like changing the value of note from \"ends with ,\" to \"ends with } \" when applied to a string containing commas.\n\nTo remove trailing commas correctly, you must track whether you are inside a string and watch for backslash escapes. A proper solution would be to use a function like remove_trailing_commas(text: str) -> str, which appends characters to a list while tracking string and escape state. It removes the comma only if it is outside a string and the next non-whitespace character closes an object or array.\n\nIn summary, repair only trailing commas outside strings, as they have a single defensible fix. Fail loudly with a line and column for other issues. This approach ensures the integrity of the JSON data.",
  "summary": "A single comma can make a whole JSON file unusable: { \"name\" : \"ada\" , \"roles\" : [ \"admin\" , \"ops\" ,], } # Python json.decoder.JSONDecodeError: Expecting value: line 3 column 28 (char 46) # Node / Chrome SyntaxError: Unexpected token ']', ...\"n\", \"ops\",], }\" is not valid JSON Both parsers stop at the first problem, the comma inside the array. Fix that one, and the comma before the final } fails…",
  "key_points": [
    "Trailing commas in JSON cause parsing errors",
    "Simple re.sub fix corrupts string values",
    "Proper solution tracks string state and escapes"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}