Any BigQuery SQL user up to solve a challenge? :gi...
# contributing-to-airbyte
c
Any BigQuery SQL user up to solve a challenge? 🎁 How do you cleanly extract a json column from this example? 1. I have one solution that is not so acceptable because it modifies the json value data… 2. the other twos are throwing errors from BigQuery • But in ideal, I would want a column named:
column_'with"_quotes
(which may not be possible in BQ) • or maybe I might be ok with another name such as
column__with__quotes
• and my row should still have the value of:
How to extract this json "column_'with"_quotes" in BigQuery?
Copy code
with example_json_data as (
  select
    "{'column_\'with\"_quotes': 'How to extract this json \"column_\'with\"_quotes\" in BigQuery?'}" as nested_json
)
select 
  json_extract(
      replace(`nested_json`, "column_'with\"_quotes", "column__with__quotes"), "$['column__with__quotes']" -- but i don't want to modify the data value!
      --`nested_json`, '$."column_\'with\"_quotes"' -- throws error: Invalid token in JSONPath at: ."column_'with"_quotes"
      --`nested_json`, "$['column_\'with\"_quotes']" -- throws error: Invalid token in JSONPath at: ['column_'with"_quotes']
    ) as column__with__quotes
from example_json_data
c
it seems like it comes down to what BQ support, right? does BQ not support quotation marks in column names?
u
if that's the case then it seems like you just got to normalize the column names.
u
is that how you were thinking about it in the approach that "modifies" the data?
u
or was that something else?
u
Doing it in sql query with the way i proposed here modifies the column name but the content data too ... Which is not ideal
u
ah
u
If i do it in java i can apply it to the column name only (by properly parsing the json)
c
yeah. modifying the value doesn't seem great. and we have to modify the value in the sql query because of a dbt implementation constraint?
u
No it s pure bq constraint
u
I dont know how to refer to a json field with quotes with jsonpath in biquery
u
oh i see.
u
Other desrinations do have some support for that
u
how does java help?
u
It s valid json where quotes are escaped so i can parse from string to json, normalise just the column/field name and reserialise to string
c
oh as in you would do it before you insert into the databse in the first place?
u
With java yes (etl)
u
Unless we can figure how to do it in bigquery in sql (elt)
u
Have you tried to contact Google?
u
I have the support package(the $150/month one), I can ask it for you.
u
that's a good point. i think we have a support package, but if we don't we'll take you up on it.
u
i kinda think just doing it in java isn't the end of the world for the bigquery-normalized destination? i guess for normal bigquery it feels weirder, but if that's what we gotta do 🤷‍♀️
c
I feel u
u
@Chris (deprecated profile) what do you think? happy to discuss more if it will be helpful.