apache/beam · error · UnsupportedRowJsonException

Expected JSON array for field '{name}'. Instead got {jsonNod

Error message

Expected JSON array for field '{name}'. Instead got {jsonNodeType}

What it means

For ARRAY-typed schema fields, jsonArrayToList expects the JSON value to be an array. Any other JSON node type (object, string, number) triggers UnsupportedRowJsonException reporting the actual Jackson node type received.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/util/RowJson.java:366

                + "'. Unable to convert '"
                + rowFieldValue.jsonValue().asText()
                + "' to Beam Row, it is not a JSON object. Currently only JSON objects can be parsed to Beam Rows");
      }

      return rowFieldValue.rowSchema().getFields().stream()
          .map(
              schemaField ->
                  extractJsonNodeValue(
                      FieldValue.of(
                          schemaField.getName(),
                          schemaField.getType(),
                          rowFieldValue.jsonFieldValue(schemaField.getName()))))
          .collect(toRow(rowFieldValue.rowSchema()));
    }

    private Object jsonArrayToList(FieldValue arrayFieldValue) {
      if (!arrayFieldValue.isJsonArray()) {
        throw new UnsupportedRowJsonException(
            "Expected JSON array for field '"
                + arrayFieldValue.name()
                + "'. Instead got "
                + arrayFieldValue.jsonNodeType().name());
      }

      return arrayFieldValue
          .jsonArrayElements()
          .map(
              jsonArrayElement ->
                  extractJsonNodeValue(
                      FieldValue.of(
                          arrayFieldValue.name() + "[]",
                          arrayFieldValue.arrayElementType(),
                          jsonArrayElement)))
          .collect(toImmutableList());
    }

View on GitHub (pinned to 12126d8942)

Solutions

  1. Make the JSON value a proper array, e.g. "tags": ["single"]
  2. Adjust the schema field type to match the real JSON shape
  3. Normalize scalar-to-array in a pre-parse transformation
  4. Catch UnsupportedRowJsonException to flag malformed records

Example fix

// before
{"tags": "a"}
// after
{"tags": ["a"]}
Defensive patterns

Strategy: validation

Validate before calling

JsonNode n = json.get("arrayField");
if (n != null && !n.isArray()) throw new IllegalArgumentException("Array field must be a JSON array, got " + n.getNodeType());

Try / catch

try { Row r = RowJsonUtils.jsonToRow(mapper, json); } catch (RowJson.UnsupportedRowJsonException e) { /* handle */ }

Prevention

When it happens

Trigger: jsonToRow where an ARRAY<...> schema field receives a non-array JSON value, e.g. "tags": "single" or "tags": {"a":1}.

Common situations: Producer wraps a single element without making it a list; object-shaped JSON where an array was expected; schema/codegen drift between writer and reader.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/553d2305104906f1. Report an issue: GitHub.