bigframes.bigquery.json_extract_string_array#
- bigframes.bigquery.json_extract_string_array(input: Series, json_path: str = '$', value_dtype: BooleanDtype | Float64Dtype | Int64Dtype | StringDtype | ArrowDtype | GeometryDtype | Literal['boolean', 'Float64', 'Int64', 'int64[pyarrow]', 'string', 'string[pyarrow]', 'timestamp[us, tz=UTC][pyarrow]', 'timestamp[us][pyarrow]', 'date32[day][pyarrow]', 'time64[us][pyarrow]', 'decimal128(38, 9)[pyarrow]', 'decimal256(76, 38)[pyarrow]', 'binary[pyarrow]', 'duration[us][pyarrow]'] | None = None) Series[source]#
Extracts a JSON array and converts it to a SQL array of STRING values. A value_dtype can be provided to further coerce the data type of the values in the array. This function uses single quotes and brackets to escape invalid JSONPath characters in JSON keys.
Deprecated since version 2.6.0: The
json_extract_string_arrayis deprecated and will be removed in a future version. Usejson_value_arrayinstead.Examples:
>>> import bigframes.pandas as bpd >>> import bigframes.bigquery as bbq
>>> s = bpd.Series(['[1, 2, 3]', '[4, 5]']) >>> bbq.json_extract_string_array(s) 0 ['1' '2' '3'] 1 ['4' '5'] dtype: list<item: string>[pyarrow]
>>> bbq.json_extract_string_array(s, value_dtype='Int64') 0 [1 2 3] 1 [4 5] dtype: list<item: int64>[pyarrow]
>>> s = bpd.Series([ ... '{"fruits": {"color": "red", "names": ["apple","cherry"]}}', ... '{"fruits": {"color": "green", "names": ["guava", "grapes"]}}' ... ]) >>> bbq.json_extract_string_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.
value_dtype (dtype, Optional) – The data type supported by BigFrames DataFrame.
- Returns:
A new Series with the parsed arrays from the input.
- Return type: