airbnb/lottie-android · error · JsonDataException
Expected BEGIN_OBJECT but was {} at path {}
Error message
Expected BEGIN_OBJECT but was {} at path {} What it means
JsonUtf8Reader.beginObject() peeks the next token and expects PEEKED_BEGIN_OBJECT ('{'). If the token is anything else, it throws JsonDataException. This occurs when the Lottie parser expects a JSON object at a specific path but finds a different type — e.g., a layer definition that should be an object is instead an array or primitive.
Source
Thrown at lottie/src/main/java/com/airbnb/lottie/parser/moshi/JsonUtf8Reader.java:150
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());
}
}
@Override public void endObject() throws IOException {
int p = peeked;
if (p == PEEKED_NONE) {
p = doPeek();
}
if (p == PEEKED_END_OBJECT) {
stackSize--;
pathNames[stackSize] = null; // Free the last path name so that it can be garbage collected!
pathIndices[stackSize - 1]++;
peeked = PEEKED_NONE;
} else {
throw new JsonDataException("Expected END_OBJECT but was " + peek()
+ " at path " + getPath());
}View on GitHub (pinned to 05ea92e903)
Solutions
- Use the path from the exception to locate the offending field and verify it is a JSON object as expected.
- Validate with LottieFiles validator and a JSON schema checker.
- Re-export the animation from a compatible tool version.
Defensive patterns
Strategy: try-catch
Try / catch
LottieTask<LottieComposition> task = LottieCompositionFactory.fromAsset(context, name);
task.addListener(result -> { /* success */ })
.addFailureListener(e -> { /* JSON object structure error */ }); Prevention
- Validate Lottie JSON structure with LottieFiles validator.
- Use async LottieCompositionFactory APIs for graceful error handling.
- Re-export from supported tool versions.
When it happens
Trigger: A field expected to be a JSON object (layer, keyframe, transform, etc.) is instead an array, string, number, or null. This means the JSON structure does not match the Lottie schema at that location.
Common situations: Non-standard Lottie JSON export; corrupted or hand-edited file where object braces were removed; version incompatibility between the animation format and the library.
Related errors
- Expected END_OBJECT but was {} at path {}
- Expected BEGIN_ARRAY but was {} at path {}
- Expected END_ARRAY but was {} at path {}
- Expected a name but was {} at path {}
- Expected a string but was {} at path {}
AI-assisted analysis of airbnb/lottie-android@05ea92e903 (2026-08-14).
Data as JSON: /api/errors/2ef9967f3c8e2a82.
Report an issue: GitHub.