pyflink.table.expression.Expression.json_value#
- Expression.json_value(path: str, returning_type: pyflink.table.types.DataType = VarCharType(2147483647, true), on_empty: pyflink.table.expression.JsonValueOnEmptyOrError = JsonValueOnEmptyOrError.NULL, default_on_empty: Optional[Any] = None, on_error: pyflink.table.expression.JsonValueOnEmptyOrError = JsonValueOnEmptyOrError.NULL, default_on_error: Optional[Any] = None) pyflink.table.expression.Expression [source]#
Extracts a scalar from a JSON string.
This method searches a JSON string for a given path expression and returns the value if the value at that path is scalar. Non-scalar values cannot be returned. By default, the value is returned as DataTypes.STRING(). Using returningType a different type can be chosen, with the following types being supported:
STRING
BOOLEAN
INT
DOUBLE
For empty path expressions or errors a behavior can be defined to either return null, raise an error or return a defined default value instead.
seealso::
json_query()
Examples:
>>> lit('{"a": true}').json_value('$.a') # STRING: 'true' >>> lit('{"a.b": [0.998,0.996]}').json_value("$.['a.b'][0]", DataTypes.DOUBLE()) # DOUBLE: 0.998 >>> lit('{"a": true}').json_value('$.a', DataTypes.BOOLEAN()) # BOOLEAN: True >>> lit('{"a": true}').json_value('lax $.b', JsonValueOnEmptyOrError.DEFAULT, False) # BOOLEAN: False >>> lit('{"a": true}').json_value('strict $.b', JsonValueOnEmptyOrError.NULL, None, JsonValueOnEmptyOrError.DEFAULT, False) # BOOLEAN: False
New in version 1.12.0.