JSON_EXTRACT

Translation reference to convert the Teradata functions JSONExtractValue, JSONExtractLargeValue and JSONExtract to Snowflake Scripting.

Description

As per Teradata’s documentation, these functions use the JSONPath Query Syntaxarrow-up-right to request information about a portion of a JSON instance. The entity desired can be any portion of a JSON instance, such as a name/value pair, an object, an array, an array element, or a value.

For more information regarding Teradata JSONExtractValue, JSONExtractLargeValue and JSONExtract, check herearrow-up-right.

JSON_expr.JSONExtractValue(JSONPath_expr)

JSON_expr.JSONExtractLargeValue(JSONPath_expr)

JSON_expr.JSONExtract(JSONPath_expr)

The JSON_EXTRACT_UDF is a Snowflake implementation of the JSONPath specification that uses a modified version of the original JavaScript implementation developed by Stefan Goessnerarrow-up-right.

Sample Source Pattern

Teradata

SELECT
    Store.JSONExtract('$..author') as AllAuthors,
    Store.JSONExtractValue('$..book[2].title') as ThirdBookTitle,
    Store.JSONExtractLargeValue('$..book[2].price') as ThirdBookPrice
FROM BookStores;

Snowflake Scripting

Known Issues

1. Elements inside JSONs may not retain their original order.

Elements inside a JSON are ordered by their keys when inserted in a table. Thus, the query results might differ. However, this does not affect the order of arrays inside the JSON.

For example, if the original JSON is:

Using the Snowflake PARSE_JSON()arrow-up-right that interprets an input string as a JSON document, producing a VARIANT value. The inserted JSON will be:

Note how "age" is now the first element. However, the array of "cities" maintains its original order.

  1. MSCEWI1020arrow-up-right: Custom UDF inserted.

Last updated

Was this helpful?