“Unexpected token” or “Unexpected end of JSON input” can make a small typo feel like a data problem. In many cases, the data is fine and the document simply breaks one of JSON’s strict punctuation rules. A missing quote, an extra comma, or a bracket in the wrong place is enough to stop a parser.
The reliable approach is to read the error location as a clue, inspect the nearby characters, and fix the smallest confirmed problem. Avoid changing several parts at once: a second edit can hide the original cause or accidentally change a value. The examples below use standard JSON, not JavaScript object-literal syntax.
Start by locating the first syntax error
JSON parsers read from the beginning and stop when the next character cannot legally follow what came before. The reported position, line, or column often marks where parsing became impossible, not necessarily where the original typo occurred. If the parser says it expected a property name after an opening brace, for example, look just before that point for a missing quote or a comma in the wrong place.
Make a copy before editing anything important. Then check whether the input is meant to be JSON at all. Comments, unquoted keys, single-quoted strings, and expressions such as undefined are familiar in JavaScript but do not belong to standard JSON. The JSON data-interchange standard, RFC 8259, defines the permitted syntax. If a file intentionally uses a JSON-like format with comments or trailing commas, confirm what its consumer expects rather than silently converting it.
Remove commas that come after the last item
A comma separates two members or array elements; it does not come after the final one. This is one of the most common differences between permissive coding styles and strict JSON.
{
"name": "Mira",
"roles": ["editor", "reviewer",]
}
The comma after "reviewer" is trailing. Remove it:
{
"name": "Mira",
"roles": ["editor", "reviewer"]
}
Check both arrays and objects, especially after deleting an item or editing the last property. A comma between items is still required, so do not remove every comma in the structure. In a long file, search for comma-before-closing-bracket patterns, but inspect each match: punctuation inside a quoted string is ordinary text.
Use double quotes for keys and string values
JSON requires double quotation marks around property names and string values. Single quotes do not count as JSON quotes, and a bare property name is invalid.
{ name: 'Mira', "active": true }
Correct form:
{ "name": "Mira", "active": true }
Only the property name active needs a string quote pair; true is a JSON boolean and must remain unquoted. The same distinction applies to false and null. Numbers are also written as numbers, not quoted, unless the application specifically treats them as text. Do not run a broad replace from apostrophes to quotes without checking the data: an apostrophe inside a sentence is content, not a string delimiter.
Repair escape sequences inside strings
Inside a JSON string, a quotation mark ends the string unless it is escaped with a backslash. A backslash itself also needs escaping when it is meant literally. This is a frequent source of trouble in file paths, regular expressions, and text copied from another format.
Escape quotes and backslashes
This string closes too early at the quotation mark before ready:
{ "message": "She said "ready"" }
Escape the embedded quotes so the parser treats them as part of the value:
{ "message": "She said "ready"" }
For a Windows path, each literal backslash is escaped in JSON. For example, represent C:\notes\plan.txt as C:\\notes\\plan.txt. In JavaScript source code, another layer of string escaping may be involved; distinguish the characters in the JSON text from the programming-language string that contains it.
Check control characters and Unicode escapes
Use the JSON escapes \n and \t for a newline and tab inside a string rather than inserting an unescaped control character. A Unicode escape has the form \u followed by four hexadecimal digits, such as \u00E9. If a backslash is intended to display as a character, escape it as \\. Watch for accidental sequences such as \q, which are not valid JSON escapes.
Match every opening and closing bracket
Objects open with { and close with }; arrays open with [ and close with ]. Each nested level must close in the reverse order in which it opened. A useful manual check is to indent each level and pair the delimiters while moving through the document.
{
"profile": {
"name": "Mira",
"skills": ["writing", "testing"]
}
}
If a parser reports the input ended unexpectedly, look for a closing brace or bracket that was never supplied, or a string that began but never closed. If the error appears around a closing delimiter, inspect the item immediately before it for an extra comma, an unfinished value, or a mismatched bracket. Nested structures are easier to debug when formatted across multiple lines rather than kept minified.
Check the value after each colon and comma
Every object member has a quoted key, a colon, and a value. Legal values are strings, numbers, objects, arrays, true, false, or null. These patterns are invalid: a colon with no value, two commas in a row, an equals sign instead of a colon, or a JavaScript value such as NaN.
For example, {"count":} has no value after its colon. Decide what the data should actually mean, then use an appropriate value such as 0 or null; do not choose one just to silence the parser. Likewise, a syntactically valid JSON document can still have the wrong fields or data types for an API. Parsing checks grammar, not whether the content meets an application’s schema or business rules.
Format and validate after making a repair
Once you have corrected a likely typo, parse the entire document again. The Kinsad JSON Formatter accepts standard JSON, lets you format valid input with two spaces, four spaces, or tabs, and includes a Minify action. Both actions parse the input first, so invalid JSON produces an error and no formatted output. It is a formatter and validator - not an automatic repair tool. It reports a parser error, but you still need to decide what correction preserves the intended data.
Work incrementally: make one change, validate, and then continue if another error appears. The first syntax issue can mask later ones. After the document parses, compare the result with the source or expected structure. Formatting can make nesting readable, but it cannot tell whether a value is factually correct, a field is missing, or an API expects a different shape. Do not paste secrets or sensitive records into a tool unless its data handling suits your requirements; for critical material, use a trusted local parser in your development environment.
A quick checklist before you move on
- Are all object keys and string values enclosed in double quotes?
- Are commas only between members or elements, never after the last item?
- Are embedded quotes and backslashes escaped?
- Does every opening brace or bracket have the matching closing character?
- Does each object key have a colon and a valid value?
- Are comments, undefined values, and JavaScript expressions removed or converted intentionally?
- Does the corrected document still have the values and structure your application expects?
For a broader introduction to objects, arrays, and JSON values, read JSON for Beginners. Keep a known-good copy while debugging, and favor the smallest repair that restores valid syntax.
Frequently asked questions
Can a formatter fix invalid JSON automatically?
A formatter can parse and reformat valid JSON. The Kinsad formatter reports a syntax error rather than guessing how to alter invalid input. That distinction matters because several different edits might make malformed text parse, while only one may preserve its intended meaning.
Why does the error location seem wrong?
A parser often reports the first character it cannot accept. The actual cause may be just before that character, such as a missing quote or comma, so inspect a few characters on both sides of the reported location.
Are comments or trailing commas allowed in JSON?
Not in standard JSON. Some configuration formats extend JSON with comments or trailing commas, but support depends on the specific parser. Check the file’s documented format and use a compatible parser rather than assuming every consumer accepts extensions.