Skip to content

bigfunctions > json_values

json_values

Call or Deploy json_values ?

✅ You can call this json_values bigfunction directly from your Google Cloud Project (no install required).

  • This json_values function is deployed in bigfunctions GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error).
  • Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework

Public BigFunctions Datasets:

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...

Description

Signature

json_values(json_string)

Description

Extract values from json_string which has only flat (no nested) key-values. Return values as an array<string>

Examples

select bigfunctions.eu.json_values('{"created_at": "2022-01-01", "user": "sidali"}')
select bigfunctions.us.json_values('{"created_at": "2022-01-01", "user": "sidali"}')
select bigfunctions.europe_west1.json_values('{"created_at": "2022-01-01", "user": "sidali"}')
+--------------------------+
| values                   |
+--------------------------+
| ['2022-01-01', 'sidali'] |
+--------------------------+

Need help using json_values?

The community can help! Engage the conversation on Slack

For professional suppport, don't hesitate to chat with us.

Found a bug using json_values?

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

For professional suppport, don't hesitate to chat with us.

Use cases

You have a table in BigQuery that stores JSON strings representing user activity. Each JSON string contains key-value pairs where the keys represent activity types and the values represent timestamps or user IDs. You want to extract all the values from these JSON strings to analyze the different types of activities performed without needing to know the specific keys.

Example Table:

UserID ActivityJSON
1 {"login": "2023-10-26 10:00:00", "purchase": "item123"}
2 {"logout": "2023-10-26 10:15:00", "view_product": "item456"}
3 {"login": "2023-10-26 10:30:00", "add_to_cart": "item789"}

Query using json_values:

SELECT
    UserID,
    bigfunctions.us.json_values(ActivityJSON) AS ActivityValues
FROM
    `your_project.your_dataset.your_table`;

Result:

UserID ActivityValues
1 ['2023-10-26 10:00:00', 'item123']
2 ['2023-10-26 10:15:00', 'item456']
3 ['2023-10-26 10:30:00', 'item789']

Now you have an array of values for each user, which you can further process. For instance, you could unnest the array to analyze the frequency of different activity values or join it with another table based on these values. The key benefit here is that you've extracted the relevant data without needing to explicitly parse the JSON based on individual keys. This is particularly useful when the keys in the JSON strings can vary across different rows but the values themselves hold the information you're interested in.

Spread the word

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on