This week we’re going to be undoing what people usually do and we’re going to be turning a table into a JSON VARIANT object.
Here we have a table with info on a set of superheroes, your job is to turn this table into a JSON VARIANT object.
Here’s the start-up code
CREATE OR REPLACE TABLE week_14 ( superhero_name varchar(50), country_of_residence varchar(50), notable_exploits varchar(150), superpower varchar(100), second_superpower varchar(100), third_superpower varchar(100) ); INSERT INTO week_14 VALUES ('Superpig', 'Ireland', 'Saved head of Irish Farmer\'s Association from terrorist cell', 'Super-Oinks', NULL, NULL); INSERT INTO week_14 VALUES ('Señor Mediocre', 'Mexico', 'Defeated corrupt convention of fruit lobbyists by telling anecdote that lasted 33 hours, with 16 tangents that lead to 17 resignations from the board', 'Public speaking', 'Stamp collecting', 'Laser vision'); INSERT INTO week_14 VALUES ('The CLAW', 'USA', 'Horrifically violent duel to the death with mass murdering super villain accidentally created art installation last valued at $14,450,000 by Sotheby\'s', 'Back scratching', 'Extendable arms', NULL); INSERT INTO week_14 VALUES ('Il Segreto', 'Italy', NULL, NULL, NULL, NULL); INSERT INTO week_14 VALUES ('Frosty Man', 'UK', 'Rescued a delegation of data engineers from a DevOps conference', 'Knows, by memory, 15 definitions of an obscure codex known as "the data mesh"', 'can copy and paste from StackOverflow with the blink of an eye', NULL);
Remember if you want to participate:
- Sign up as a member of Frosty Friday. You can do this by clicking on the sidebar, and then going to ‘REGISTER‘ (note joining our mailing list does not give you a Frosty Friday account)
- Post your code to GitHub and make it publicly available (Check out our guide if you don’t know how to here)
- Post the URL in the comments of the challenge.
seemingly simple but not quite
That was a nice way to demonstrate how easily you can create/manipulate JSON data with Snowflake
I have to admit I’m more used to do the opposite of this 🙂
– Create a base table to insert the values.
– Create a second view with the objects.
Quite an easy one this week. Good practice if you want to build an API on top of Snowflake to expose some of your data.
My solution for this weekly challenge
Pekka Kanerva says
Nice refresher on how to generate json out of relational table.
A great way to familiar yourself with arrays and Json structure.
A Fun one!
My Solution for week 14
Jamie Laird says
Another great challenge. Learned some basic but handy stuff here.
Good to try some basic ones to learn the documents in more details.