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

  1. Add the missing ']' to close the array at the reported parse position
  2. Verify the producer of the JSON emits the complete array (check for truncation/limits)
  3. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/8e1cf1100ce8578a. Report an issue: GitHub.