Skip to main content
Ctrl+K
PyFlink 1.20+vvr.11.7.dev0 documentation - Home PyFlink 1.20+vvr.11.7.dev0 documentation - Home
  • API Reference
  • Examples
  • API Reference
  • Examples

Section Navigation

  • PyFlink Table
    • TableEnvironment
    • Table
    • Data Types
    • Window
    • Expressions
    • User Defined Functions
    • Descriptors
    • StatementSet
    • Catalog
  • PyFlink DataStream
  • PyFlink DataFrame
  • PyFlink Common
  • API Reference
  • PyFlink Table
  • Expressions
  • pyflink.table.expression.Expression.json_value

pyflink.table.expression.Expression.json_value#

Expression.json_value(path: str, returning_type: DataType = VarCharType(2147483647, true), on_empty: JsonValueOnEmptyOrError = JsonValueOnEmptyOrError.NULL, default_on_empty: Any | None = None, on_error: JsonValueOnEmptyOrError = JsonValueOnEmptyOrError.NULL, default_on_error: Any | None = None) → 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.

See also

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

Added in version 1.12.0.

previous

pyflink.table.expression.Expression.json_exists

next

pyflink.table.expression.Expression.json_query

On this page
  • Expression.json_value()

This Page

  • Show Source

Created using Sphinx 7.4.7.

Built with the PyData Sphinx Theme 0.16.1.