airbnb/lottie-android · error · JsonDataException

Expected a double but was {} at path {}

Error message

Expected a double but was {} at path {}

What it means

JsonUtf8Reader.nextDouble() peeks the next token expecting a numeric value (PEEKED_LONG, PEEKED_NUMBER) or a string that can be parsed as a double (double-quoted, single-quoted, unquoted, buffered). If the token is none of these (boolean, null, object/array start, EOF), it throws JsonDataException. A second throw occurs inside the method if the string-to-double parse fails (NumberFormatException) or if the result is NaN/Infinity in non-lenient mode. This fires when a numeric property in the Lottie JSON has an invalid or wrong-typed value.

Source

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

      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);
    } else if (p == PEEKED_SINGLE_QUOTED) {
      peekedString = nextQuotedValue(SINGLE_QUOTE_OR_SLASH);
    } else if (p == PEEKED_UNQUOTED) {
      peekedString = nextUnquotedValue();
    } else if (p != PEEKED_BUFFERED) {
      throw new JsonDataException("Expected a double but was " + peek() + " at path " + getPath());
    }

    peeked = PEEKED_BUFFERED;
    double result;
    try {
      result = Double.parseDouble(peekedString);
    } catch (NumberFormatException e) {
      throw new JsonDataException("Expected a double but was " + peekedString
          + " at path " + getPath());
    }
    if (!lenient && (Double.isNaN(result) || Double.isInfinite(result))) {
      throw new JsonEncodingException("JSON forbids NaN and infinities: " + result
          + " at path " + getPath());
    }
    peekedString = null;
    peeked = PEEKED_NONE;
    pathIndices[stackSize - 1]++;
    return result;

View on GitHub (pinned to 05ea92e903)

Solutions

  1. Use the exception path to locate the field and ensure it contains a valid JSON number.
  2. If the field is a string-encoded number, ensure it's parseable as Double.parseDouble().
  3. Re-export or re-download the animation to fix corrupted data.
Defensive patterns

Strategy: try-catch

Try / catch

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

Prevention

When it happens

Trigger: A property expected to be a number (opacity, rotation, scale, time offset, etc.) is a boolean, null, object, or array. Or, the value is a string that cannot be parsed as a double (e.g., "abc"). Or, the value is NaN/Infinity in strict mode. Each triggers a different variant of the same exception message.

Common situations: Malformed Lottie JSON with wrong-typed numeric fields; animation exported with string-encoded numbers that aren't parseable; corrupted file causing token type mismatch; edge case with NaN/Infinity in numeric literals.

Related errors


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