Skip to content
Advertisement

Parse JSON like VARCHAR Column in Snowflake

I have a VARCHAR column called TAG within a SQL database with the data looking like the example below.

Example:

Since it is not a JSON column, I am having difficulty parsing through the column to get the postScore value.

I have tried to convert this from a VARCHAR to Variant datatype so that I can do something like the following to get the

Any help on how I can go about getting that postScore value from this Varchar column would be appreciated!

Advertisement

Answer

You can do this with parse_json and a flatten. Note that your JSON has a problem with it. Notice that your first quote character at the beginning of the word google is a weird double-quote that may cause you problems: "url":”google.com" is different from ".

Anyway, assuming that your quote was an error with your copy-paste and not actually a problem with your actual JSON then you can do it like this:

Query

Sample table I used

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement