2222from __future__ import annotations
2323
2424from typing import Any , cast , Optional , Sequence , Tuple , Union
25+ import warnings
2526
2627import bigframes .core .utils as utils
2728import bigframes .dtypes
29+ import bigframes .exceptions as bfe
2830import bigframes .operations as ops
2931import bigframes .series as series
3032
@@ -87,9 +89,13 @@ def json_extract(
8789 input : series .Series ,
8890 json_path : str ,
8991) -> series .Series :
90- """Extracts a JSON value and converts it to a SQL JSON-formatted `STRING` or `JSON`
91- value. This function uses single quotes and brackets to escape invalid JSONPath
92- characters in JSON keys.
92+ """Extracts a JSON value and converts it to a SQL JSON-formatted ``STRING`` or
93+ ``JSON`` value. This function uses single quotes and brackets to escape invalid
94+ JSONPath characters in JSON keys.
95+
96+ .. deprecated:: 2.5.0
97+ The ``json_extract`` is deprecated and will be removed in a future version.
98+ Use ``json_query`` instead.
9399
94100 **Examples:**
95101
@@ -111,6 +117,11 @@ def json_extract(
111117 Returns:
112118 bigframes.series.Series: A new Series with the JSON or JSON-formatted STRING.
113119 """
120+ msg = (
121+ "The `json_extract` is deprecated and will be removed in a future version. "
122+ "Use `json_query` instead."
123+ )
124+ warnings .warn (bfe .format_message (msg ), category = UserWarning )
114125 return input ._apply_unary_op (ops .JSONExtract (json_path = json_path ))
115126
116127
@@ -231,6 +242,37 @@ def json_extract_string_array(
231242 return array_series
232243
233244
245+ def json_query (
246+ input : series .Series ,
247+ json_path : str ,
248+ ) -> series .Series :
249+ """Extracts a JSON value and converts it to a SQL JSON-formatted ``STRING``
250+ or ``JSON`` value. This function uses double quotes to escape invalid JSONPath
251+ characters in JSON keys. For example: ``"a.b"``.
252+
253+ **Examples:**
254+
255+ >>> import bigframes.pandas as bpd
256+ >>> import bigframes.bigquery as bbq
257+ >>> bpd.options.display.progress_bar = None
258+
259+ >>> s = bpd.Series(['{"class": {"students": [{"id": 5}, {"id": 12}]}}'])
260+ >>> bbq.json_query(s, json_path="$.class")
261+ 0 {"students":[{"id":5},{"id":12}]}
262+ dtype: string
263+
264+ Args:
265+ input (bigframes.series.Series):
266+ The Series containing JSON data (as native JSON objects or JSON-formatted strings).
267+ json_path (str):
268+ The JSON path identifying the data that you want to obtain from the input.
269+
270+ Returns:
271+ bigframes.series.Series: A new Series with the JSON or JSON-formatted STRING.
272+ """
273+ return input ._apply_unary_op (ops .JSONQuery (json_path = json_path ))
274+
275+
234276def json_value (
235277 input : series .Series ,
236278 json_path : str ,
0 commit comments