Skip to content

[FEATURE] Add json_valid as a PPL function #3207

@acarbonetto

Description

@acarbonetto

Is your feature request related to a problem?
As part of the RFC to add JSON functions, the json_valid function would be useful to validate incoming json-encoded strings.

What solution would you like?

Note: The Jackson data-bind library is already available in opensearch-sql to validate json-encoded strings.

### `JSON_VALID`

**Description**

`json_valid(jsonStr)` Evaluates whether a json-encoded string contains valid JSON syntax and returns TRUE or FALSE.

**Argument type:** STRING

**Return type:** BOOLEAN

Example:

    os> source=people | eval `valid_json` = json_valid('[1,2,3,4]'), `invalid_json` = json_valid('{"invalid": "json"') | fields `valid_json`, `invalid_json`
    fetched rows / total rows = 1/1
    +--------------+----------------+
    | valid_json   | invalid_json   |
    +--------------+----------------+
    | True         | False          |
    +--------------+----------------+

    os> source=accounts | where json_valid('[1,2,3,4]') and isnull(email) | fields account_number, email
    fetched rows / total rows = 1/1
    +------------------+---------+
    | account_number   | email   |
    |------------------+---------|
    | 13               | null    |
    +------------------+---------+

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions