Class JsonToRow

java.lang.Object
org.apache.beam.sdk.transforms.JsonToRow

public class JsonToRow extends Object
Creates a PTransform to convert input JSON objects to Rows with given Schema.

Currently supported Schema field types are:

For specifics of JSON deserialization see RowJson.RowJsonDeserializer.

Conversion is strict, with minimal type coercion:

Booleans are only parsed from true or false literals, not from "true" or "false" strings or any other values (exception is thrown in these cases).

If a JSON number doesn't fit into the corresponding schema field type, an exception is be thrown. Strings are not auto-converted to numbers. Floating point numbers are not auto-converted to integral numbers. Precision loss also causes exceptions.

Only JSON string values can be parsed into Schema.TypeName.STRING. Numbers, booleans are not automatically converted, exceptions are thrown in these cases.

If a schema field is missing from the JSON value, by default the field will be assumed to have a null value, and will be converted into a null in the row if the schema has this field being nullable. This behavior can be changed by setting the RowJson.RowJsonDeserializer.NullBehavior using the withSchemaAndNullBehavior(org.apache.beam.sdk.schemas.Schema, org.apache.beam.sdk.util.RowJson.RowJsonDeserializer.NullBehavior). For example, setting it with RowJson.RowJsonDeserializer.NullBehavior.REQUIRE_NULL means that JSON values must be null to be parsed as null, otherwise an error will be thrown, as with previous versions of Beam.