File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
packages/python/plotly/plotly Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 8
8
from copy import deepcopy , copy
9
9
import itertools
10
10
from functools import reduce
11
+ import json
11
12
12
13
from _plotly_utils .utils import (
13
14
_natural_sort_strings ,
17
18
display_string_positions ,
18
19
chomp_empty_strings ,
19
20
find_closest_string ,
21
+ PlotlyJSONEncoder ,
20
22
)
21
23
from _plotly_utils .exceptions import PlotlyKeyError
22
24
from .optional_imports import get_module
@@ -3316,14 +3318,26 @@ def to_dict(self):
3316
3318
3317
3319
def to_plotly_json (self ):
3318
3320
"""
3319
- Convert figure to a JSON representation as a Python dict
3321
+ Convert figure to a JSON representation as a Python dict.
3322
+
3323
+ Note: May include some JSON-invalid data types, use the `PlotlyJSONEncoder` util when encoding.
3320
3324
3321
3325
Returns
3322
3326
-------
3323
3327
dict
3324
3328
"""
3325
3329
return self .to_dict ()
3326
3330
3331
+ def to_json_str (self ):
3332
+ """
3333
+ Convert to a JSON string representation.
3334
+
3335
+ Returns
3336
+ -------
3337
+ str
3338
+ """
3339
+ return json .dumps (self .to_plotly_json (), cls = PlotlyJSONEncoder )
3340
+
3327
3341
@staticmethod
3328
3342
def _to_ordered_dict (d , skip_uid = False ):
3329
3343
"""
@@ -5603,6 +5617,16 @@ def to_plotly_json(self):
5603
5617
"""
5604
5618
return deepcopy (self ._props if self ._props is not None else {})
5605
5619
5620
+ def to_json_str (self ):
5621
+ """
5622
+ Convert to a JSON string representation.
5623
+
5624
+ Returns
5625
+ -------
5626
+ str
5627
+ """
5628
+ return json .dumps (self .to_plotly_json (), cls = PlotlyJSONEncoder )
5629
+
5606
5630
@staticmethod
5607
5631
def _vals_equal (v1 , v2 ):
5608
5632
"""
You can’t perform that action at this time.
0 commit comments