0 0
Read Time:1 Minute, 31 Second

During this post we will discuss about how to handle JSON via javascript functions. Though there are many Javascript functions which we can leverage in our Snowflake stored procedure. But for this post we will discuss about two key JS functions  to handle JSON data. Also Please note I am not well versed with  javascript programming but thanks to other blogs who helped me to implement the below procedure. We will be discussing  JSON.parse () and JSON.stringify() functions to process the JSON data.

JSON.parse () :Parse the data with JSON.parse(), and the data becomes a JavaScript object

JSON.stringify(): static method converts a JavaScript value to a JSON string.

Lets try to understand these functions with practical examples.

  • When we fetch the JSON value without any parsing. Observe the output of the v_jsonval.
Proc Without JS Function
  • Now comment the first part and enable the JSON.PARSE and observe the output.
Proc With JSON.parse()
  • Now Try to insert the Javascript object value without any conversion.
No Conversion for JSON value
  • Use the JSON.stringify() method converts a JavaScript value to a JSON string.

A table gets created with JSON values.

JSON Table output

In the end, someone can ask why we need these JSON.parse () and JSON.stringify() and we can achieve this with simple approach like this:

Proc with No Conversion

But I wanted to highlight above functions w.r.t to Snowflake Scripting procedure. We can follow above procedure as well.

Average Rating

5 Star
4 Star
3 Star
2 Star
1 Star

Leave a Reply

Your email address will not be published. Required fields are marked *