Skip to main content

Command Palette

Search for a command to run...

Dynamically extracting JSON data in BigQuery

Updated
1 min read
Dynamically extracting JSON data in BigQuery
C

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified

I was asked today about dynamically extracting key-value pairs from heterogeneous JSON-like strings in BigQuery SQL and I've remembered this interesting approach I've seen a while ago.

It leverages regular expressions, one of everyone's favorites, I know.

This allows extraction of key-value pairs from each JSON-like string, even if they are don't look the same.

Kudos to someone on Stack Overflow where I've first seen it.

Pretty sure the regex can be streamlined, but that's as much me feat. GPT could do today.

PS. If we're talking about JSON datatype, you can transform it to JSON-like STRING with TO_JSON_STRING() and do the same thing.

Found it useful? Subscribe to my Analytics newsletter at notjustsql.com.


Enjoyed this? Here are some related articles you might find useful:

More from this blog

D

Datawise: A blog on SQL, BigQuery, Analytics, Python Tips and Tricks

204 posts

Data Engineer with a passion for transforming complex data landscapes into insightful stories. Here on my blog, I share insights, challenges, and the ever-evolving dance of technology and business.