All Products
Search
Document Center

Realtime Compute for Apache Flink:PARSE_JSON

Last Updated:Jun 10, 2025

Converts a JSON string into a VARIANT value.

Limits

This function is supported only in Ververica Runtime (VVR) 11.1.0 or later.

Syntax

VARIANT PARSE_JSON(VARCHAR jsonStr [, BOOLEAN allowDuplicateKeys])

Arguments

Argument

Data type

Description

jsonStr

VARCHAR

The JSON string to be parsed.

Note

If the input is NULL, the function returns NULL.

allowDuplicateKeys

BOOLEAN

This optional argument specifies whether duplicate keys are allowed. Valid values:

  • true: Retains the value of the last duplicate key in the JSON string.

  • false (default): Reports an error if duplicate keys exist in the JSON string.

Comparison of PARSE_JSON and TRY_PARSE_JSON

Function

Error handling mechanism

Return value for invalid JSON input

Suitable scenarios

PARSE_JSON

Explicitly raises errors.

Returns an error.

Strict input validation is required.

TRY_PARSE_JSON

Tolerates errors.

Returns NULL.

Tolerance for invalid input is needed.

Example

  • Test data in the T1 table:

    jsonString(VARCHAR)

    {"k": "v1", "k2": 1}

  • Test statement:

    SELECT PARSE_JSON(jsonString) AS v
    FROM T1; 
  • Results:

    v

    (VARIANT)

    {"k": "v1", "k2": 1}