Could somebody help me to create an SQL statement to flatten JSON data in Snowflake Table1 table, in one JSON_DATA column that has an array?
JSON_DATA:
{
"scopes": [
{
"scope_name": "IN SCOPE",
"company_code": "01",
"lob_codes": ["01","07","09"]
},
{
"scope_name": "IN SCOPE",
"company_code": "02",
"lob_codes": ["07","13","20"]
},
{
"scope_name": "OUT OF SCOPE",
"company_code": "01",
"lob_codes": ["30","35","40"]
},
{
"scope_name": "OUT OF SCOPE",
"company_code": "02",
"lob_codes": ["02","03","05"]
}
]
}
I need to flatten it to:
|scope_name | company_code| lob_codes|
|--------------|----------------|------------|
|IN SCOPE | 1 | 01 |
|IN SCOPE | 1 | 07 |
|IN SCOPE | 1 | 09 |
|IN SCOPE | 2 | 07 |
|IN SCOPE | 2 | 13 |
|IN SCOPE | 2 | 20 |
|OUT OF SCOPE | 1 | 30 |
|OUT OF SCOPE | 1 | 35 |
|OUT OF SCOPE | 1 | 40 |
|OUT OF SCOPE | 2 | 02 |
|OUT OF SCOPE | 2 | 03 |
|OUT OF SCOPE | 2 | 05 |