Ctrl+K
Logo image Logo image

Site Navigation

  • API Reference
  • Examples

Site Navigation

  • API Reference
  • Examples

Section Navigation

  • PyFlink Table
    • TableEnvironment
    • Table
    • Data Types
    • Window
    • Expressions
    • User Defined Functions
    • Descriptors
    • StatementSet
    • Catalog
  • PyFlink DataStream
  • PyFlink Common

pyflink.table.expression.Expression.json_query#

Expression.json_query(path: str, wrapping_behavior=JsonQueryWrapper.WITHOUT_ARRAY, on_empty=JsonQueryOnEmptyOrError.NULL, on_error=JsonQueryOnEmptyOrError.NULL) → pyflink.table.expression.Expression[source]#

Extracts JSON values from a JSON string.

This follows the ISO/IEC TR 19075-6 specification for JSON support in SQL. The result is always returned as a STRING.

The wrapping_behavior determines whether the extracted value should be wrapped into an array, and whether to do so unconditionally or only if the value itself isn’t an array already.

on_empty and on_error determine the behavior in case the path expression is empty, or in case an error was raised, respectively. By default, in both cases null is returned. Other choices are to use an empty array, an empty object, or to raise an error.

seealso:: json_value()

Examples:

>>> lit('{"a":{"b":1}}').json_query('$.a') # '{"b":1}'
>>> lit('[1,2]').json_query('$') # '[1,2]'
>>> null_of(DataTypes.STRING()).json_query('$') # None

>>> lit('{}').json_query('$', JsonQueryWrapper.CONDITIONAL_ARRAY) # '[{}]'
>>> lit('[1,2]').json_query('$', JsonQueryWrapper.CONDITIONAL_ARRAY) # '[1,2]'
>>> lit('[1,2]').json_query('$', JsonQueryWrapper.UNCONDITIONAL_ARRAY) # '[[1,2]]'

>>> lit(1).json_query('$') # null
>>> lit(1).json_query('$', JsonQueryWrapper.CONDITIONAL_ARRAY) # '[1]'

>>> lit('{}').json_query('lax $.invalid', JsonQueryWrapper.WITHOUT_ARRAY,                                      JsonQueryOnEmptyOrError.EMPTY_OBJECT,                                     JsonQueryOnEmptyOrError.NULL) # '{}'
>>> lit('{}').json_query('strict $.invalid', JsonQueryWrapper.WITHOUT_ARRAY,                                      JsonQueryOnEmptyOrError.NULL,                                      JsonQueryOnEmptyOrError.EMPTY_ARRAY) # '[]'

New in version 1.12.0.

previous

pyflink.table.expression.Expression.json_value

next

User Defined Functions

Show Source

Created using Sphinx 4.5.0.