@@ -429,6 +429,13 @@ def clean_to_json_compatible(obj, **kwargs):
429
429
if isinstance (obj , (int , float , string_types )):
430
430
return obj
431
431
432
+ if isinstance (obj , dict ):
433
+ return {k : clean_to_json_compatible (v , ** kwargs ) for k , v in obj .items ()}
434
+ elif isinstance (obj , (list , tuple )):
435
+ if obj :
436
+ # Must process list recursively even though it may be slow
437
+ return [clean_to_json_compatible (v , ** kwargs ) for v in obj ]
438
+
432
439
# unpack kwargs
433
440
numpy_allowed = kwargs .get ("numpy_allowed" , False )
434
441
datetime_allowed = kwargs .get ("datetime_allowed" , False )
@@ -439,12 +446,6 @@ def clean_to_json_compatible(obj, **kwargs):
439
446
pd = modules ["pd" ]
440
447
image = modules ["image" ]
441
448
442
- # Plotly
443
- try :
444
- obj = obj .to_plotly_json ()
445
- except AttributeError :
446
- pass
447
-
448
449
# Sage
449
450
if sage_all is not None :
450
451
if obj in sage_all .RR :
@@ -522,6 +523,12 @@ def clean_to_json_compatible(obj, **kwargs):
522
523
if image is not None and isinstance (obj , image .Image ):
523
524
return ImageUriValidator .pil_image_to_uri (obj )
524
525
526
+ # Plotly
527
+ try :
528
+ obj = obj .to_plotly_json ()
529
+ except AttributeError :
530
+ pass
531
+
525
532
# Recurse into lists and dictionaries
526
533
if isinstance (obj , dict ):
527
534
return {k : clean_to_json_compatible (v , ** kwargs ) for k , v in obj .items ()}
0 commit comments