All Products
Search
Document Center

MaxCompute:JSON_OBJECT

Last Updated:Jul 28, 2023

Generates a JSON object in the key-value format.

Syntax

json json_object(<key1>,<value1>[,<keyn>,<valuen>])

Parameters

  • key: You must specify at least one key. The key must be of the STRING type.

  • value: You must specify at least one value. The value must be of the STRING, BIGINT, INT, or BOOLEAN type.

Return value

The return value is of the JSON type.

Examples

  • Example 1: Generate a JSON object that contains only one key-value pair.

    -- Generate a JSON object.
    select json_object('a', 123);

    The following result is returned:

    +-----+
    | _c0 |
    +-----+
    | {"a":123} |
    +-----+
  • Example 2: Generate a JSON object that contains multiple key-value pairs.

    -- Generate a JSON object.
    select json_object('a', 123,'b','hello');

    The following result is returned:

    +-----+
    | _c0 |
    +-----+
    | {"a":123,"b":"hello"} |
    +-----+

Related functions

JSON_OBJECT is a complex type function. For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.