quarkusio/quarkus · error · IllegalArgumentException
Json array ended without ]
Error message
Json array ended without ]
What it means
readArray() consumes elements inside '[' ... ']'. If the input ends before a closing ']' is reached, the array is unterminated and the reader throws IllegalArgumentException. Like the missing '}' case, it signals an unbalanced or truncated JSON document.
Source
Thrown at independent-projects/bootstrap/json/src/main/java/io/quarkus/bootstrap/json/JsonReader.java:156
final List<JsonValue> elements = new ArrayList<>();
while (position < length) {
ignoreWhitespace();
switch (peekChar()) {
case ']':
position++;
return new JsonArray(elements);
case ',':
position++;
break;
default:
elements.add(readElement());
break;
}
}
throw new IllegalArgumentException("Json array ended without ]");
}
/**
* string
* |---- '"' characters '"'
* </p>
* characters
* |----- ""
* |----- character characters
* </p>
* character
* |----- '0020' . '10FFFF' - '"' - '\'
* |----- '\' escape
* |----- escape
* |----- '"'
* |----- '\'
* |----- '/'
* |----- 'b'View on GitHub (pinned to e1c734241f)
Solutions
- Add the missing ']' to close the array at the reported parse position
- Verify the producer of the JSON emits the complete array (check for truncation/limits)
- Validate the document with a JSON validator before parsing
Example fix
// before String json = "[1, 2, 3"; // after String json = "[1, 2, 3]";
Defensive patterns
Strategy: try-catch
Validate before calling
long opens = jsonText.chars().filter(c -> c == '[').count();
long closes = jsonText.chars().filter(c -> c == ']').count();
if (opens != closes) {
throw new IllegalArgumentException("Unbalanced brackets in JSON input");
} Try / catch
try {
JsonValue v = new JsonReader(text).read();
} catch (IllegalArgumentException e) {
if (e.getMessage().equals("Json array ended without ]")) {
// treat as truncated payload: retry the fetch or repair the document
}
} Prevention
- Ensure array producers emit the full array including the closing ']'
- Avoid manual string concatenation for arrays; use a serializer
- Check pagination/streaming code for premature termination
When it happens
Trigger: A JSON array literal without a closing ']', e.g. '[1, 2, 3' or nested arrays cut short like '[{"a": 1,' with the outer ']' missing.
Common situations: Streaming/paginated JSON cut mid-array; manual string building dropping the final bracket; serialization interrupted midway.
Related errors
- Json array ended without ]
- Control characters not allowed in json string
- String not closed
- Unable to read json constant for: %s
- Unable to fully read json value
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/8e1cf1100ce8578a.
Report an issue: GitHub.