In BigQuery, how to filter on json for rows with a condition on a subelement?

1.2k Views Asked by At

We use json_extract to extract fields for data in BigQuery I can easily filter by event_type, but how can I filter by title extracted from the JSON? for example: only titles that contain the word "facebook"

if I query by operation it works perfectly:

SELECT timestamp,
operation as event_type,
json_extract(data, '$.title') as title,
json_extract(data, '$.duration') as duration,
FROM `videos` 
WHERE (operation = "CREATE") ORDER BY timestamp ASC
1

There are 1 best solutions below

0
On

Dose this work?

SELECT timestamp,
operation as event_type,
json_extract(data, '$.title') as title,
json_extract(data, '$.duration') as duration,
FROM `videos` 
WHERE operation = "CREATE"
  and json_value(data, '$.title') like '%facebook%'
ORDER BY timestamp ASC