Skip to content

[FEATURE] Add json function to cast nested to json object #3216

Closed

Description

@acarbonetto

Is your feature request related to a problem?

As part of the RFC to add JSON functions, the json() function would be useful to cast a nested object as a JSON_OBJECT using the json() function or cast(nested to json) syntax.

What solution would you like?

  • Add the json(nested) function that constructs a JSON_OBJECT from a nested object
  • Add the cast(nested to json) casting syntax to cast a nested object to a JSON_OBJECT
  • Update documentation and mapping
### `JSON`

**Description**

`json(value)` Unnests a NESTED object and casts it into a JSON object. 

**Argument type:** NESTED OBJECT

**Return type:** JSON OBJECT

Example:

    os> source=people | eval unnested_json = json(nested) | fields unnested_json
    fetched rows / total rows = 1/1
    +---------------------------------+
    | unnested_json                      |
    +---------------------------------+
    | {'name': 'Timmy', 'location': 'Seattle'   |
    +---------------------------------+

JSON Cast:

Example:

    os> source=people | eval unnested_json = cast(nested to json) | fields unnested_json
    fetched rows / total rows = 1/1
    +---------------------------------+
    | unnested_json                      |
    +---------------------------------+
    | {'name': 'Timmy', 'location': 'Seattle'   |
    +---------------------------------+

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 function to cast nested to json object #3209[/-] [+][FEATURE] Add json function to cast nested to json object[/+] on Dec 19, 2024
  2. changed the title [-][FEATURE] Add json function to cast nested to json object[/-] [+][FEATURE] Add `json` function to cast nested to json object[/+] 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