From 6c6a85e8cb4dbc29c577cdfcec1509da5089f9d5 Mon Sep 17 00:00:00 2001 From: Ben Bellick Date: Tue, 11 Nov 2025 11:29:11 -0500 Subject: [PATCH 1/2] feat: add simple extension for JSON --- extensions/json.yaml | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 extensions/json.yaml diff --git a/extensions/json.yaml b/extensions/json.yaml new file mode 100644 index 000000000..ea1f7f9fe --- /dev/null +++ b/extensions/json.yaml @@ -0,0 +1,61 @@ +%YAML 1.2 +--- +urn: extension:io.substrait:json +types: + - name: json + structure: + content: string + description: >- + A JSON type representing arbitrary JSON values (objects, arrays, + strings, numbers, booleans, or null). + +scalar_functions: + - name: "parse_json" + description: >- + Parse a JSON string into a JSON value. + impls: + - args: + - name: json_string + value: string + options: + on_error: + description: Controls behavior when input is not valid JSON + values: [ ERROR, "NULL" ] + return: u!json? + + - name: "to_string" + description: "Convert a JSON value to its string representation" + impls: + - args: + - name: json_value + value: u!json + return: string + + - name: "json_extract" + description: >- + Extract a value from JSON using a JSONPath expression. + JSONPath expressions should follow RFC 9535 (https://datatracker.ietf.org/doc/html/rfc9535). + impls: + - args: + - name: json_value + value: u!json + - name: path + value: string + options: + on_invalid_path: + description: Controls behavior when the JSONPath expression is syntactically invalid + values: [ ERROR, "NULL", UNDEFINED ] + on_path_not_found: + description: Controls behavior when the path does not exist in the JSON document + values: [ ERROR, "NULL" ] + return: u!json? + + - name: "is_json_valid" + description: >- + Returns true if the input string is valid JSON, false otherwise. + This function does not parse the JSON, only validates syntax. + impls: + - args: + - name: json_string + value: string + return: boolean From 914e6b1ff0a9f9ee2f7aef920314c3350bf1e439 Mon Sep 17 00:00:00 2001 From: Ben Bellick Date: Tue, 11 Nov 2025 19:03:05 -0500 Subject: [PATCH 2/2] tweak: fix @yongchul's comments --- extensions/json.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/extensions/json.yaml b/extensions/json.yaml index ea1f7f9fe..910a5b4b5 100644 --- a/extensions/json.yaml +++ b/extensions/json.yaml @@ -12,19 +12,20 @@ types: scalar_functions: - name: "parse_json" description: >- - Parse a JSON string into a JSON value. + Parses a JSON string into a JSON value. impls: - args: - name: json_string value: string options: on_error: - description: Controls behavior when input is not valid JSON + description: Controls behavior when input is not valid JSON. values: [ ERROR, "NULL" ] return: u!json? - name: "to_string" - description: "Convert a JSON value to its string representation" + description: >- + Converts a JSON value to its string representation. impls: - args: - name: json_value @@ -33,7 +34,7 @@ scalar_functions: - name: "json_extract" description: >- - Extract a value from JSON using a JSONPath expression. + Extracts a value from JSON using a JSONPath expression. JSONPath expressions should follow RFC 9535 (https://datatracker.ietf.org/doc/html/rfc9535). impls: - args: @@ -43,10 +44,10 @@ scalar_functions: value: string options: on_invalid_path: - description: Controls behavior when the JSONPath expression is syntactically invalid + description: Controls behavior when the JSONPath expression is syntactically invalid. values: [ ERROR, "NULL", UNDEFINED ] on_path_not_found: - description: Controls behavior when the path does not exist in the JSON document + description: Controls behavior when the path does not exist in the JSON document. values: [ ERROR, "NULL" ] return: u!json?