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.expressions.json_object#

json_object(on_null: pyflink.table.expression.JsonOnNull = JsonOnNull.NULL, *args) → pyflink.table.expression.Expression[source]#

Builds a JSON object string from a list of key-value pairs.

args is an even-numbered list of alternating key/value pairs. Note that keys must be non-NULL string literals, while values may be arbitrary expressions.

This function returns a JSON string. The on_null behavior defines how to treat NULL values.

Values which are created from another JSON construction function call (json_object, json_array) are inserted directly rather than as a string. This allows building nested JSON structures.

Examples:

>>> json_object() # '{}'
>>> json_object(JsonOnNull.NULL, "K1", "V1", "K2", "V2") # '{"K1":"V1","K2":"V2"}'

>>> # Expressions as values
>>> json_object(JsonOnNull.NULL, "orderNo", col("orderId"))

>>> json_object(JsonOnNull.NULL, "K1", null_of(DataTypes.STRING()))   # '{"K1":null}'
>>> json_object(JsonOnNull.ABSENT, "K1", null_of(DataTypes.STRING())) # '{}'

>>> # '{"K1":{"K2":"V"}}'
>>> json_object(JsonOnNull.NULL, "K1", json_object(JsonOnNull.NULL, "K2", "V"))

See also

json_array()

New in version 1.12.0.

previous

pyflink.table.expressions.json_string

next

pyflink.table.expressions.json_object_agg

Show Source

Created using Sphinx 4.5.0.