@@ -212,6 +212,34 @@ def test_json_extract_string_array_w_invalid_series_type():
212212 bbq .json_extract_string_array (s )
213213
214214
215+ def test_json_value_from_json ():
216+ s = bpd .Series (
217+ ['{"a": {"b": [1, 2]}}' , '{"a": {"c": 1}}' , '{"a": {"b": 0}}' ],
218+ dtype = dtypes .JSON_DTYPE ,
219+ )
220+ actual = bbq .json_value (s , "$.a.b" )
221+ expected = bpd .Series ([None , None , "0" ], dtype = dtypes .STRING_DTYPE )
222+
223+ pd .testing .assert_series_equal (actual .to_pandas (), expected .to_pandas ())
224+
225+
226+ def test_json_value_from_string ():
227+ s = bpd .Series (
228+ ['{"a": {"b": [1, 2]}}' , '{"a": {"c": 1}}' , '{"a": {"b": 0}}' ],
229+ dtype = pd .StringDtype (storage = "pyarrow" ),
230+ )
231+ actual = bbq .json_value (s , "$.a.b" )
232+ expected = bpd .Series ([None , None , "0" ], dtype = dtypes .STRING_DTYPE )
233+
234+ pd .testing .assert_series_equal (actual .to_pandas (), expected .to_pandas ())
235+
236+
237+ def test_json_value_w_invalid_series_type ():
238+ s = bpd .Series ([1 , 2 ])
239+ with pytest .raises (TypeError ):
240+ bbq .json_value (s , "$.a" )
241+
242+
215243def test_parse_json_w_invalid_series_type ():
216244 s = bpd .Series ([1 , 2 ])
217245 with pytest .raises (TypeError ):
0 commit comments