I am ingesting .json data into Google BigQuery, and on the ingest, the data types for arrays and objects from the .json are both being cast into string columns. The data in BigQuery then looks like this:
select 1 as id, '[]' as stringCol1, '[]' as stringCol2 union all
select 2 as id, null as stringCol1, null as stringCol2 union all
select 3 as id, "{'game': '22', 'year': 'sophomore'}" as stringCol1, "[{'teamName': 'teamA', 'teamAge': 37}, {'teamName': 'teamB', 'teamAge': 32]" as stringCol2 union all
select 4 as id, "{'game': '17', 'year': 'freshman'}" as stringCol1, "[{'teamName': 'teamA', 'teamAge': 32}, {'teamName': 'teamB', 'teamAge': 33]" as stringCol2 union all
select 5 as id, "{'game': '9', 'year': 'senior'}" as stringCol1, "[{'teamName': 'teamC', 'teamAge': 31}, {'teamName': 'teamD', 'teamAge': 17]" as stringCol2 union all
select 6 as id, "{'game': '234', 'year': 'junior'}" as stringCol1, "[{'teamName': 'teamC', 'teamAge': 42}, {'teamName': 'teamD', 'teamAge': 25]" as stringCol2
The data is a bit messy.
- In
stringCol1, there are bothnulland'[]'values for missing data. I'd like to create the 2 columnsgameandyearfrom this stringified object. - For
stringCol2, this is always an array with 2 objects, with identical keys (teamNameandteamAge, in this case). This then needs to be cast into the 4 columnsteamName1,teamAge1,teamName2,teamAge2.
This similar post addressed converting a basic stringified array into a not-stringified array, but this example here is a bit more complex. In particular, the solution in that other post does not work in this case.
