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 88from copy import deepcopy , copy
99import itertools
1010from functools import reduce
11+ import json
1112
1213from _plotly_utils .utils import (
1314 _natural_sort_strings ,
1718 display_string_positions ,
1819 chomp_empty_strings ,
1920 find_closest_string ,
21+ PlotlyJSONEncoder ,
2022)
2123from _plotly_utils .exceptions import PlotlyKeyError
2224from .optional_imports import get_module
@@ -3316,14 +3318,26 @@ def to_dict(self):
33163318
33173319 def to_plotly_json (self ):
33183320 """
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.
33203324
33213325 Returns
33223326 -------
33233327 dict
33243328 """
33253329 return self .to_dict ()
33263330
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+
33273341 @staticmethod
33283342 def _to_ordered_dict (d , skip_uid = False ):
33293343 """
@@ -5603,6 +5617,16 @@ def to_plotly_json(self):
56035617 """
56045618 return deepcopy (self ._props if self ._props is not None else {})
56055619
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+
56065630 @staticmethod
56075631 def _vals_equal (v1 , v2 ):
56085632 """
You can’t perform that action at this time.
0 commit comments