airbnb/lottie-android · error · JsonDataException

Expected BEGIN_ARRAY but was {} at path {}

Error message

Expected BEGIN_ARRAY but was {} at path {}

What it means

JsonUtf8Reader.beginArray() peeks the next token and expects PEEKED_BEGIN_ARRAY ('['). If the actual token is anything else (object, string, number, etc.), it throws JsonDataException with the actual token and current path. This enforces structural expectations during Lottie JSON parsing — properties that must be arrays (keyframe arrays, point arrays, etc.) must actually be arrays.

Source

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

    }
    this.source = source;
    // Don't use source.getBuffer(). Because android studio use old version okio instead of your own okio.
    this.buffer = source.buffer();
    pushScope(JsonScope.EMPTY_DOCUMENT);
  }


  @Override public void beginArray() throws IOException {
    int p = peeked;
    if (p == PEEKED_NONE) {
      p = doPeek();
    }
    if (p == PEEKED_BEGIN_ARRAY) {
      pushScope(JsonScope.EMPTY_ARRAY);
      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());
    }
  }

View on GitHub (pinned to 05ea92e903)

Solutions

  1. Use the path in the exception message to find the exact field, then verify its JSON type matches what the Lottie schema expects (array in this case).
  2. Validate the animation with LottieFiles validator.
  3. Re-export the animation from a supported version of After Effects + Bodymovin/LottieFiles plugin.
Defensive patterns

Strategy: try-catch

Try / catch

LottieTask<LottieComposition> task = LottieCompositionFactory.fromAsset(context, name);
task.addListener(result -> { /* success */ })
     .addFailureListener(e -> {
         if (e instanceof JsonDataException) {
             // structural type mismatch — JSON is malformed
         }
     });

Prevention

When it happens

Trigger: The parser calls beginArray() expecting an array but encounters a different JSON structure — e.g., a property that should be an array of keyframes is instead a single object, number, or string. This typically means the Lottie JSON deviates from the expected schema at that location.

Common situations: Malformed or non-standard Lottie JSON where an array-typed field is encoded as a different type; animation exported by an incompatible tool version; hand-edited JSON where array brackets were accidentally removed.

Related errors


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