Skip to content
37 changes: 37 additions & 0 deletions packages/python/plotly/plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3318,6 +3318,8 @@ def to_plotly_json(self):
"""
Convert figure to a JSON representation as a Python dict

Note: May include some JSON-invalid data types, use the `PlotlyJSONEncoder` util when encoding.

Returns
-------
dict
Expand Down Expand Up @@ -5597,12 +5599,47 @@ def to_plotly_json(self):
"""
Return plotly JSON representation of object as a Python dict

Note: May include some JSON-invalid data types, use the `PlotlyJSONEncoder` util when encoding.

Returns
-------
dict
"""
return deepcopy(self._props if self._props is not None else {})

def to_json(self, *args, **kwargs):
"""
Convert object to a JSON string representation

Parameters
----------
validate: bool (default True)
True if the object should be validated before being converted to
JSON, False otherwise.

pretty: bool (default False)
True if JSON representation should be pretty-printed, False if
representation should be as compact as possible.

remove_uids: bool (default True)
True if trace UIDs should be omitted from the JSON representation

engine: str (default None)
The JSON encoding engine to use. One of:
- "json" for an encoder based on the built-in Python json module
- "orjson" for a fast encoder the requires the orjson package
If not specified, the default encoder is set to the current value of
plotly.io.json.config.default_encoder.

Returns
-------
str
Representation of object as a JSON string
"""
import plotly.io as pio

return pio.to_json(self, *args, **kwargs)

@staticmethod
def _vals_equal(v1, v2):
"""
Expand Down