search

Home  >  Q&A  >  body text

Way to remove double quotes and convert data type to string in Google BigQuery

<p>The values ​​are of JSON object type and I want to change them to strings and remove the double quote symbols. I tried the replace and trim functions but they require strings as input. <br />I also tried the replace, trim and cast functions, but they require the input to be in string format. <br />Select replace(cast([column name] as string), """) from [table name]</p>
P粉481035232P粉481035232510 days ago530

reply all(1)I'll reply

  • P粉966979765

    P粉9669797652023-08-16 10:29:05

    To convert a JSON column to STRING, you can use the JSON_EXTRACT_SCALAR function. Example:

    WITH sample AS (
      SELECT JSON '[{"day_of_week": "SUNDAY", "from": "06:00:00", "to": "15:00:00"}]' as json_data
    )
    SELECT
      JSON_EXTRACT_SCALAR(j.day_of_week) as day_of_week,
      JSON_EXTRACT_SCALAR(j.from) as `from`,
      JSON_EXTRACT_SCALAR(j.to) as `to`
    FROM sample, UNNEST(JSON_EXTRACT_ARRAY(sample.json_data)) j
    

    Output results:

    reply
    0
  • Cancelreply