File tree 2 files changed +35
-0
lines changed 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 38
38
json_extract_array ,
39
39
json_extract_string_array ,
40
40
json_set ,
41
+ json_value ,
41
42
parse_json ,
42
43
)
43
44
from bigframes .bigquery ._operations .search import create_vector_index , vector_search
61
62
"json_extract" ,
62
63
"json_extract_array" ,
63
64
"json_extract_string_array" ,
65
+ "json_value" ,
64
66
"parse_json" ,
65
67
# search ops
66
68
"create_vector_index" ,
Original file line number Diff line number Diff line change @@ -231,6 +231,39 @@ def json_extract_string_array(
231
231
return array_series
232
232
233
233
234
+ def json_value (
235
+ input : series .Series ,
236
+ json_path : str ,
237
+ ) -> series .Series :
238
+ """Extracts a JSON scalar value and converts it to a SQL ``STRING`` value. In
239
+ addtion, this function:
240
+ - Removes the outermost quotes and unescapes the values.
241
+ - Returns a SQL ``NULL`` if a non-scalar value is selected.
242
+ - Uses double quotes to escape invalid ``JSON_PATH`` characters in JSON keys.
243
+
244
+ **Examples:**
245
+
246
+ >>> import bigframes.pandas as bpd
247
+ >>> import bigframes.bigquery as bbq
248
+ >>> bpd.options.display.progress_bar = None
249
+
250
+ >>> s = bpd.Series(['{"name": "Jakob", "age": "6"}'])
251
+ >>> bbq.json_value(s, json_path="$.age")
252
+ 0 6
253
+ dtype: string
254
+
255
+ Args:
256
+ input (bigframes.series.Series):
257
+ The Series containing JSON data (as native JSON objects or JSON-formatted strings).
258
+ json_path (str):
259
+ The JSON path identifying the data that you want to obtain from the input.
260
+
261
+ Returns:
262
+ bigframes.series.Series: A new Series with the JSON-formatted STRING.
263
+ """
264
+ return input ._apply_unary_op (ops .JSONValue (json_path = json_path ))
265
+
266
+
234
267
@utils .preview (name = "The JSON-related API `parse_json`" )
235
268
def parse_json (
236
269
input : series .Series ,
You can’t perform that action at this time.
0 commit comments