@@ -434,3 +434,53 @@ def test_to_json_string_from_struct():
434434 )
435435
436436 pd .testing .assert_series_equal (actual .to_pandas (), expected .to_pandas ())
437+
438+
439+ def test_json_keys ():
440+ json_data = [
441+ '{"name": "Alice", "age": 30}' ,
442+ '{"city": "New York", "country": "USA", "active": true}' ,
443+ "{}" ,
444+ '{"items": [1, 2, 3]}' ,
445+ ]
446+ s = bpd .Series (json_data , dtype = dtypes .JSON_DTYPE )
447+ actual = bbq .json_keys (s )
448+
449+ expected_data_pandas = [
450+ ["age" , "name" ],
451+ [
452+ "active" ,
453+ "city" ,
454+ "country" ,
455+ ],
456+ [],
457+ ["items" ],
458+ ]
459+ expected = bpd .Series (
460+ expected_data_pandas , dtype = pd .ArrowDtype (pa .list_ (pa .string ()))
461+ )
462+ pd .testing .assert_series_equal (actual .to_pandas (), expected .to_pandas ())
463+
464+
465+ def test_json_keys_with_max_depth ():
466+ json_data = [
467+ '{"user": {"name": "Bob", "details": {"id": 123, "status": "approved"}}}' ,
468+ '{"user": {"name": "Charlie"}}' ,
469+ ]
470+ s = bpd .Series (json_data , dtype = dtypes .JSON_DTYPE )
471+ actual = bbq .json_keys (s , max_depth = 2 )
472+
473+ expected_data_pandas = [
474+ ["user" , "user.details" , "user.name" ],
475+ ["user" , "user.name" ],
476+ ]
477+ expected = bpd .Series (
478+ expected_data_pandas , dtype = pd .ArrowDtype (pa .list_ (pa .string ()))
479+ )
480+ pd .testing .assert_series_equal (actual .to_pandas (), expected .to_pandas ())
481+
482+
483+ def test_json_keys_from_string_error ():
484+ s = bpd .Series (['{"a": 1, "b": 2}' , '{"c": 3}' ])
485+ with pytest .raises (TypeError ):
486+ bbq .json_keys (s )
0 commit comments