airbnb/lottie-android · error · JsonDataException
Expected END_ARRAY but was
Error message
Expected END_ARRAY but was {} at path {} What it means
JsonUtf8Reader.endArray() peeks the next token and expects PEEKED_END_ARRAY (']'). If the actual token differs — for example, the stream has an extra element or the wrong delimiter — it throws JsonDataException with the actual token and current path. This fires when the parser finishes reading array elements but the JSON does not properly close the array.
Solutions
- Use the exception's path to locate the malformed array in the JSON and fix its structure (ensure proper brackets and commas).
- Run the JSON through a standard JSON linter to catch structural errors.
- Re-download or re-export the animation file.
Defensive patterns
Strategy: try-catch
Try / catch
LottieTask<LottieComposition> task = LottieCompositionFactory.fromAsset(context, name);
task.addListener(result -> { /* success */ })
.addFailureListener(e -> { /* JSON array structure error */ }); Prevention
- Validate Lottie JSON with a JSON linter.
- Use async APIs to handle parse failures gracefully.
- Re-export or re-download corrupted animations.
When it happens
Trigger: The parser expects the closing ']' of an array but encounters a different token: a missing comma producing an unexpected value, extra elements beyond what the parser consumed, or a structural corruption that shifts the reader's position.
Common situations: Corrupted Lottie JSON with missing or misplaced array delimiters; truncated file; JSON edited by hand with comma or bracket errors.
Related errors
- Expected BEGIN_ARRAY but was
- Expected a boolean but was
- Expected a double but was
- Expected a name but was
- Expected a string but was
AI-assisted analysis of airbnb/lottie-android@05ea92e903 (2026-08-14).
Data as JSON: /api/errors/c868de4adc89e5ad.
Report an issue: GitHub.
Appendix: source
Thrown at lottie/src/main/java/com/airbnb/lottie/parser/moshi/JsonUtf8Reader.java:136
pathIndices[stackSize - 1] = 0;
peeked = PEEKED_NONE;
} else {
throw new JsonDataException("Expected BEGIN_ARRAY but was " + peek()
+ " at path " + getPath());
}
}
@Override public void endArray() throws IOException {
int p = peeked;
if (p == PEEKED_NONE) {
p = doPeek();
}
if (p == PEEKED_END_ARRAY) {
stackSize--;
pathIndices[stackSize - 1]++;
peeked = PEEKED_NONE;
} else {
throw new JsonDataException("Expected END_ARRAY but was " + peek()
+ " at path " + getPath());
}
}
@Override public void beginObject() throws IOException {
int p = peeked;
if (p == PEEKED_NONE) {
p = doPeek();
}
if (p == PEEKED_BEGIN_OBJECT) {
pushScope(JsonScope.EMPTY_OBJECT);
peeked = PEEKED_NONE;
} else {
throw new JsonDataException("Expected BEGIN_OBJECT but was " + peek()
+ " at path " + getPath());
}
}
View on GitHub (pinned to 05ea92e903)