bigframes.bigquery.json_value_array#
- bigframes.bigquery.json_value_array(input: Series, json_path: str = '$') Series[source]#
Extracts a JSON array of scalar values and converts it to a SQL
ARRAY<STRING>value. In addition, this function:Removes the outermost quotes and unescapes the values.
Returns a SQL
NULLif the selected value isn’t an array or not an array containing only scalar values.Uses double quotes to escape invalid
JSON_PATHcharacters in JSON keys.
Examples:
>>> import bigframes.pandas as bpd >>> import bigframes.bigquery as bbq
>>> s = bpd.Series(['[1, 2, 3]', '[4, 5]']) >>> bbq.json_value_array(s) 0 ['1' '2' '3'] 1 ['4' '5'] dtype: list<item: string>[pyarrow]
>>> s = bpd.Series([ ... '{"fruits": ["apples", "oranges", "grapes"]', ... '{"fruits": ["guava", "grapes"]}' ... ]) >>> bbq.json_value_array(s, "$.fruits") 0 ['apples' 'oranges' 'grapes'] 1 ['guava' 'grapes'] dtype: list<item: string>[pyarrow]
>>> s = bpd.Series([ ... '{"fruits": {"color": "red", "names": ["apple","cherry"]}}', ... '{"fruits": {"color": "green", "names": ["guava", "grapes"]}}' ... ]) >>> bbq.json_value_array(s, "$.fruits.names") 0 ['apple' 'cherry'] 1 ['guava' 'grapes'] dtype: list<item: string>[pyarrow]
- Parameters:
input (bigframes.series.Series) – The Series containing JSON data (as native JSON objects or JSON-formatted strings).
json_path (str) – The JSON path identifying the data that you want to obtain from the input.
- Returns:
A new Series with the parsed arrays from the input.
- Return type: