class_docstr: Meant to be passed as the `cls` kwarg to json.dumps(obj, cls=..)
  
  See PlotlyJSONEncoder.default for more implementation information.
  
  Additionally, this encoder overrides nan functionality so that 'Inf',
  'NaN' and '-Inf' encode to 'null'. Which is stricter JSON than the Python
  version.
class_docstr_tok: ["Meant","to","be","passed","as","the","`","cls","`","kwarg","to","json.dumps","(","obj",",","cls=","..",")","See","PlotlyJSONEncoder.default","for","more","implementation","information",".","Additionally",",","this","encoder","overrides","nan","functionality","so","that","'Inf","'",",","'NaN","'","and","'-Inf","'","encode","to","'null","'",".","Which","is","stricter","JSON","than","the","Python","version","."]
docstr: Load and then dump the result using parse_constant kwarg
  
  Note that setting invalid separators will cause a failure at this step.
docstr_tok: ["Load","and","then","dump","the","result","using","parse_constant","kwarg","Note","that","setting","invalid","separators","will","cause","a","failure","at","this","step","."]
code: def encode(self, o):
      """
      Load and then dump the result using parse_constant kwarg
  
      Note that setting invalid separators will cause a failure at this step.
  
      """
      # this will raise errors in a normal-expected way
      encoded_o = super(PlotlyJSONEncoder, self).encode(o)
      # Brute force guessing whether NaN or Infinity values are in the string
      # We catch false positive cases (e.g. strings such as titles, labels etc.)
      # but this is ok since the intention is to skip the decoding / reencoding
      # step when it's completely safe
  
      if not ("NaN" in encoded_o or "Infinity" in encoded_o):
          return encoded_o
  
      # now:
      #    1. `loads` to switch Infinity, -Infinity, NaN to None
      #    2. `dumps` again so you get 'null' instead of extended JSON
      try:
          new_o = _json.loads(
              encoded_o, parse_constant=self.coerce_to_strict
          )
      except ValueError:
          # invalid separators will fail here. raise a helpful exception
          raise ValueError(
              "Encoding into strict JSON failed. Did you set the separators "
              "valid JSON separators?"
          )
      else:
          return _json.dumps(
              new_o,
              sort_keys=self.sort_keys,
              indent=self.indent,
              separators=(self.item_separator, self.key_separator),
          )
  
imports: import decimal
  import json
  import sys
  import re
  from functools import reduce
  from _plotly_utils.optional_imports import get_module
  from _plotly_utils.basevalidators import ImageUriValidator
label_desc: Use image node_id 2 for calling the PlotlyJSONEncoder obj's underlying member method code with example usage: obj.encode(o) and returns: encoded_o, _json