airbnb/lottie-android · error · JsonDataException
Expected a string but was {} at path {}
Error message
Expected a string but was {} at path {} What it means
JsonUtf8Reader.nextString() peeks the next token expecting a string-compatible value: double-quoted, single-quoted, buffered, or a number/long that can be coerced to string. Any other token type (boolean, null, object start, array start, EOF) triggers JsonDataException. This fires when the parser reads a string-typed property (e.g., layer name, refId, font family) but the JSON contains a non-string value.
Source
Thrown at lottie/src/main/java/com/airbnb/lottie/parser/moshi/JsonUtf8Reader.java:633
if (p == PEEKED_NONE) {
p = doPeek();
}
String result;
if (p == PEEKED_UNQUOTED) {
result = nextUnquotedValue();
} else if (p == PEEKED_DOUBLE_QUOTED) {
result = nextQuotedValue(DOUBLE_QUOTE_OR_SLASH);
} else if (p == PEEKED_SINGLE_QUOTED) {
result = nextQuotedValue(SINGLE_QUOTE_OR_SLASH);
} else if (p == PEEKED_BUFFERED) {
result = peekedString;
peekedString = null;
} else if (p == PEEKED_LONG) {
result = Long.toString(peekedLong);
} else if (p == PEEKED_NUMBER) {
result = buffer.readUtf8(peekedNumberLength);
} else {
throw new JsonDataException("Expected a string but was " + peek() + " at path " + getPath());
}
peeked = PEEKED_NONE;
pathIndices[stackSize - 1]++;
return result;
}
@Override public boolean nextBoolean() throws IOException {
int p = peeked;
if (p == PEEKED_NONE) {
p = doPeek();
}
if (p == PEEKED_TRUE) {
peeked = PEEKED_NONE;
pathIndices[stackSize - 1]++;
return true;
} else if (p == PEEKED_FALSE) {
peeked = PEEKED_NONE;
pathIndices[stackSize - 1]++;View on GitHub (pinned to 05ea92e903)
Solutions
- Use the exception path to locate the field and ensure its value is a JSON string.
- Validate the animation with LottieFiles validator.
- Re-export or re-download the animation.
Defensive patterns
Strategy: try-catch
Try / catch
LottieTask<LottieComposition> task = LottieCompositionFactory.fromAsset(context, name);
task.addListener(result -> { /* success */ })
.addFailureListener(e -> { /* JSON string type error */ }); Prevention
- Validate Lottie JSON with LottieFiles validator.
- Use async LottieCompositionFactory APIs for graceful error handling.
- Re-export from supported tool versions.
When it happens
Trigger: A property expected to be a string (e.g., 'nm' layer name, 'refId', 'fFamily' font family) is instead a number, boolean, null, object, or array in the Lottie JSON.
Common situations: Malformed Lottie JSON where a string field contains a non-string value; non-standard export tool; corrupted or hand-edited file.
Related errors
- Expected BEGIN_ARRAY but was {} at path {}
- Expected END_ARRAY but was {} at path {}
- Expected BEGIN_OBJECT but was {} at path {}
- Expected END_OBJECT but was {} at path {}
- Expected a name but was {} at path {}
AI-assisted analysis of airbnb/lottie-android@05ea92e903 (2026-08-14).
Data as JSON: /api/errors/5359234c7ebafc9a.
Report an issue: GitHub.