I have a string separated by commas, which are the column names in my_table.
“First_Name, Last_Name, Age”. I need to split the string with commas and fetch the columns(First_Name, Last_Name, Age) from my_table from a JSON column called custom_fields.
Here is the JSON column below:
custom_fields
{
"First_Name": "Vaibhav",
"Last_Name": "Terli",
"Age": "24"
}
Expected Output:
First_Name | Last_Name | Age
---------------------------
Vaibhav | Terli | 24
It is easier if your JSON in a VARIANT type, then you can use standard Snowflake syntax to call values from individual JSON keys. If your JSON is a string, you can use
PARSE_JSONfunction to convert it to VARIANT, see below example:Now you can select individual keys as follows:
The expected output: