Skip to content

[FEATURE] Add json_array_length function to PPL #3218

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?

### `JSON_ARRAY_LENGTH`

**Description**

`json_array_length(doc[, path])` Returns the number of elements in array at path in the JSON document. By default, path is the root of the document. Returns NULL if the element at path is not an array. 

**Argument type:** JSON_OBJECT, STRING

**Return type:** INTEGER | NULL

Example:

    os> source=people | eval `length1` = json_array_length(json('[1,2,3,4]'), '{}'), `length2` = json_array_length(json('[1,2,3,{"f1":1,"f2":[5,6]},4]', '{}[3].f2'), `not_array` = json_array_length(json('{"key": 1}', '{}')
    fetched rows / total rows = 1/1
    +-----------+-----------+-------------+
    | lenght1   | lenght2   | not_array   |
    +-----------+-----------+-------------+
    | 4         | 2         | null        |
    +-----------+-----------+-------------+

What alternatives have you considered?

N/A

Do you have any additional context?

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

Activity

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

    @LantaoJin
    Member

    Resolved by #3559 with Calcite implementation.

  5. 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