airbnb/lottie-android · error · JsonDataException

Expected a boolean but was {} at path {}

Error message

Expected a boolean but was {} at path {}

What it means

JsonUtf8Reader.nextBoolean() peeks the next token expecting PEEKED_TRUE or PEEKED_FALSE. Any other token type throws JsonDataException. This fires when the parser reads a boolean property (e.g., 'hd' hidden flag, 'ind' in some contexts, 'd' dash property) but the JSON contains a non-boolean value.

Source

Thrown at lottie/src/main/java/com/airbnb/lottie/parser/moshi/JsonUtf8Reader.java:654

    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]++;
      return false;
    }
    throw new JsonDataException("Expected a boolean but was " + peek() + " at path " + getPath());
  }

  @Override public double nextDouble() throws IOException {
    int p = peeked;
    if (p == PEEKED_NONE) {
      p = doPeek();
    }

    if (p == PEEKED_LONG) {
      peeked = PEEKED_NONE;
      pathIndices[stackSize - 1]++;
      return (double) peekedLong;
    }

    if (p == PEEKED_NUMBER) {
      peekedString = buffer.readUtf8(peekedNumberLength);
    } else if (p == PEEKED_DOUBLE_QUOTED) {
      peekedString = nextQuotedValue(DOUBLE_QUOTE_OR_SLASH);

View on GitHub (pinned to 05ea92e903)

Solutions

  1. Use the exception path to locate the field and ensure its value is a JSON boolean (true or false).
  2. If the export tool uses 0/1 for booleans, re-export with correct boolean types.
  3. Validate the JSON structure and re-download if corrupted.

Example fix

// before — numeric 0/1 where boolean is expected
{"ty":"sh","hd":1,"ks":{...}}

// after — proper JSON boolean
{"ty":"sh","hd":true,"ks":{...}}
Defensive patterns

Strategy: try-catch

Try / catch

LottieTask<LottieComposition> task = LottieCompositionFactory.fromAsset(context, name);
task.addListener(result -> { /* success */ })
     .addFailureListener(e -> { /* JSON boolean type error */ });

Prevention

When it happens

Trigger: A property expected to be a boolean (e.g., 'hd' for hidden layers, 'closed' for shape paths) is instead a number, string, null, object, or array in the Lottie JSON.

Common situations: Malformed Lottie JSON where a boolean field contains 0/1 instead of false/true (or vice versa); corrupted export; hand-edited file with type errors.

Related errors


AI-assisted analysis of airbnb/lottie-android@05ea92e903 (2026-08-14). Data as JSON: /api/errors/06aa4a5996c2ddc9. Report an issue: GitHub.