简体   繁体   中英

JSON issue in Big Query

I have scenario to parse the json data which is of one column in table. Issue is that below Response column as json generated by Datastore backup to BigQuery. It has '\\'attached to every data.

Reponse": "[
  {
    \"questionId\":5121566669012992,
    \"answereId\":0,
    \"answeredText\":\"Summer\"
  },{
    \"questionId\":5166851730440192,
    \"answereId\":0,
    \"answeredText\":\"Barcelona\"
  },{
    \"questionId\":6304057064947712,
    \"answereId\":0,
    \"answeredText\":\"Kitesurf\"
  }
]"

How do I parse the below to get value for questionId using BigQuery?

JSON_EXTRACT cannot return REPEATED field, it can only do one match - hence no support for *

you can get the first position using hardcoded indexes as

SELECT JSON_EXTRACT_SCALAR('[
  {
    \"questionId\":5121566669012992,
    \"answereId\":0,
    \"answeredText\":\"Summer\"
  },{
    \"questionId\":5166851730440192,
    \"answereId\":0,
    \"answeredText\":\"Barcelona\"
  },{
    \"questionId\":6304057064947712,
    \"answereId\":0,
    \"answeredText\":\"Kitesurf\"
  } 
]', '$[0].questionId') AS str;

This returns:

+-----+------------------+---+
| Row |       str        |   |
+-----+------------------+---+
|   1 | 5121566669012992 |   |
+-----+------------------+---+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM