Skip to content

[FEATURE] Add json_array constructor function to PPL #3217

Closed

Description

@acarbonetto

Is your feature request related to a problem?

As part of the RFC to add JSON functions, the json_array function would be useful to construct json objects with arrays.

What solution would you like?

Tasks to complete:

  • Add json_array(scalar_value) that returns an ARRAY object with scalars.
  • Add json_array(field) that returns an ARRAY object with values from the field, where field can be a multi-value.
  • Add json_array(json_object) that returns an ARRAY object with JSON_OBJECTs.
  • Add json_array(json_array) that returns a mult-dimensional ARRAY object.
  • Add json_array as part of the json_object construction; json_object(key, value [, key, value]*) -> json_object function, where value can also be a `json_array. see: [FEATURE] Add json_object constructor function to PPL #3208.
### `JSON_ARRAY`

**Description**

`json_array(<value>...)` Creates a JSON ARRAY flattening a list of multi-valued fields.

**Argument type:**
- A \<value\> can be any kind of value such as string, number, boolean, array, or json_object. 

**Return type:** ARRAY (Spark ArrayType)

An array of any supported data type for a valid JSON array.

Example:

    os> source=people | eval `json_array` = json_array(1, 2, 0, -1, 1.1, -0.11)
    fetched rows / total rows = 1/1

    +------------------------------+
    | json_array                   |
    +------------------------------+
    | [1.0,2.0,0.0,-1.0,1.1,-0.11] |
    +------------------------------+

    os> source=people | eval `json_array_object` = json_object("array", json_array(1, 2, 0, -1, 1.1, -0.11))

    fetched rows / total rows = 1/1
    +----------------------------------------+
    | json_array_object                      |
    +----------------------------------------+
    | {"array":[1.0,2.0,0.0,-1.0,1.1,-0.11]} |
    +----------------------------------------+

What alternatives have you considered?

N/A

Do you have any additional context?

opensearch-project/opensearch-spark#780 - PR to add feature to opensearch-spark PPL

Activity

  1. changed the title [-][FEATURE] Add json_array constructor function to PPL[/-] [+][FEATURE] Add `json_array` constructor function to PPL[/+] on Dec 20, 2024
  2. added
    PPL
    on May 29, 2025
  3. LantaoJin commented on Jun 16, 2025

    @LantaoJin
    Member

    Resolved by #3559 with Calcite implementation.

  4. moved this from Not Started to Done in PPL Trackeron Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PPLenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions