Expected ',' or ']' after array element in JSON
The parser has read one value in an array and needs either a comma before the next element or a closing square bracket to finish the list. A second value appears instead. Spaces make the two numbers easy for a person to distinguish, but JSON requires an explicit separator between array elements. This is an error about the gap between values, not a ban on the number or string that happens to follow the gap.
Input
[1 2]Do
- Paste the input into the validator.
- Press Repair in the editor band.
Result
Inserted missing commas
[1, 2]| Runtime | Message |
|---|---|
| Chrome 153 · Node.js 26 | Expected ',' or ']' after array element in JSON at position 3 (line 1 column 4) |
| Node.js 18 (older V8) | Unexpected number in JSON at position 3 |
| Firefox 156 | JSON.parse: expected ',' or ']' after array element at line 1 column 4 of the JSON data |
| Safari 26 | JSON Parse error: Expected ']' |
| Python 3.14 json | Expecting ',' delimiter: line 1 column 4 (char 3) |
| This site | Expected "," or "]", found "2"line 1, column 4 |
Recorded from each runtime; the wording is in Firefox’s, Safari’s and Python’s sources.
Read the position as the next value's start
In [1 2], position 3 is the digit 2, which is line 1, column 4. The parser already accepted the digit 1 and skipped the space after it. It then found the next number where only a comma or the end of the array belonged. Insert a comma after the first value to get[1, 2]; replacing the digit 2 would fix the wrong part of the text. On a long list, inspect the element immediately before the underline as well as the element that is underlined.
A misplaced separator can hide at the end of the previous line when each element is written on its own line. The line and column in the error describe where parsing became impossible, which can be several spaces or a line break after the missing comma. If the reported character begins a nested object or another array, the same reasoning applies: the preceding element needs a separator regardless of the following value's type.
Lists copied from other formats
A space-separated list from a terminal, spreadsheet export or plain-text file is not already a JSON array just because square brackets have been put around it. Some sources also omit commas in lists printed for display, making the result look close enough to copy into a configuration file. Identify how the source separates its fields and encode those fields as an array using a JSON writer. That keeps quoting rules and separators consistent when a later field contains a space of its own.
Newlines are whitespace too, so a vertical list without commas fails for the same reason as the short example. This invalid arrangement still needs a comma after the first number:
[
1
2
]An NDJSON file has a different convention: each line is its own complete JSON document. Adding brackets around that file does not insert commas between its records. Parse each known record separately, or deliberately create an array with separators when one document is required. The page about text after JSONcovers the related error you see when those same records are joined without any outer brackets.
Check the element boundary before editing
The element before the error must be complete before you can insert a comma. A string whose closing quote is missing or an object whose closing brace was dropped can make later punctuation look misplaced. Follow the surrounding brackets and quotes back to the start of that element. If they are balanced and a new value follows, adding the separator is the direct correction. If they are unbalanced, restore the missing ending before deciding whether another array element has begun.
Do not add a comma after every line as a general repair strategy: one object can occupy several lines, and the final element needs no trailing comma. Inside an array, strings can also contain comma characters that belong to their contents. A JSON encoder handles these boundaries from the structure of your data, whereas a line-by-line replacement guesses from the formatting. When a loop builds the text manually, check how it emits separators between iterations, especially around optional items.
Why Node.js 18 says Unexpected number
Current Chrome and Node.js name the comma or bracket they expected after the array element, and Firefox gives nearly the same explanation. Node.js 18's older V8 wording describes the next token instead, so it printsUnexpected number in JSON at position 3. That message can suggest the number itself is wrong even though the missing separator is the cause. Python asks for a comma delimiter at column 4, while Safari only says it expected a closing bracket. Each recorded run stops at the same boundary in this five-character input.
Inserting the comma here
Try the example in the JSON Validator to see this site's message, which names both the expected punctuation and the digit it found. Repair inserts the comma and keeps the two numbers in their original order. The result has two array elements, rather than a single string containing a space or a combined number such as 12. Compare the number of elements with your intended list before keeping the output. The walkthroughFix invalid JSONshows how to review that change alongside other common syntax mistakes.