bigframes.bigquery.json_query_array#
- bigframes.bigquery.json_query_array(input: Series, json_path: str = '$') Series[source]#
Extracts a JSON array and converts it to a SQL array of JSON-formatted STRING or JSON values. This function uses double quotes to escape invalid JSONPath characters in JSON keys. For example: “a.b”.
Examples:
>>> import bigframes.pandas as bpd >>> import bigframes.bigquery as bbq
>>> s = bpd.Series(['[1, 2, 3]', '[4, 5]']) >>> bbq.json_query_array(s) 0 ['1' '2' '3'] 1 ['4' '5'] dtype: list<item: string>[pyarrow]
>>> s = bpd.Series([ ... '{"fruits": [{"name": "apple"}, {"name": "cherry"}]}', ... '{"fruits": [{"name": "guava"}, {"name": "grapes"}]}' ... ]) >>> bbq.json_query_array(s, "$.fruits") 0 ['{"name":"apple"}' '{"name":"cherry"}'] 1 ['{"name":"guava"}' '{"name":"grapes"}'] dtype: list<item: string>[pyarrow]
>>> s = bpd.Series([ ... '{"fruits": {"color": "red", "names": ["apple","cherry"]}}', ... '{"fruits": {"color": "green", "names": ["guava", "grapes"]}}' ... ]) >>> bbq.json_query_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: