11import uuid
2- import json
32import os
43import webbrowser
54
65import six
76
7+ from _plotly_utils .optional_imports import get_module
88from plotly .io ._utils import validate_coerce_fig_to_dict
99from plotly .offline .offline import _get_jconfig , get_plotlyjs
1010from plotly import utils
1111
12+ _json = get_module ("json" )
13+
1214
1315# Build script to set global PlotlyConfig object. This must execute before
1416# plotly.js is loaded.
@@ -134,15 +136,15 @@ def to_html(
134136 plotdivid = str (uuid .uuid4 ())
135137
136138 # ## Serialize figure ##
137- jdata = json .dumps (
139+ jdata = _json .dumps (
138140 fig_dict .get ("data" , []), cls = utils .PlotlyJSONEncoder , sort_keys = True
139141 )
140- jlayout = json .dumps (
142+ jlayout = _json .dumps (
141143 fig_dict .get ("layout" , {}), cls = utils .PlotlyJSONEncoder , sort_keys = True
142144 )
143145
144146 if fig_dict .get ("frames" , None ):
145- jframes = json .dumps (fig_dict .get ("frames" , []), cls = utils .PlotlyJSONEncoder )
147+ jframes = _json .dumps (fig_dict .get ("frames" , []), cls = utils .PlotlyJSONEncoder )
146148 else :
147149 jframes = None
148150
@@ -218,7 +220,7 @@ def to_html(
218220
219221 if auto_play :
220222 if animation_opts :
221- animation_opts_arg = ", " + json .dumps (animation_opts )
223+ animation_opts_arg = ", " + _json .dumps (animation_opts )
222224 else :
223225 animation_opts_arg = ""
224226 then_animate = """.then(function(){{
@@ -228,7 +230,7 @@ def to_html(
228230 )
229231
230232 # Serialize config dict to JSON
231- jconfig = json .dumps (config )
233+ jconfig = _json .dumps (config )
232234
233235 script = """\
234236 if (document.getElementById("{id}")) {{\
0 commit comments