parameters: (description=None)
return_statement: return add_json_methods_impl
docstring: Decorator that adds 4 JSON helper methods to a class:
  
      - to_json(): Convert to JSON string
      - from_json(): Convert from JSON string
      - save(): Convert to JSON and save to file
      - load(): Load from file and convert from JSON
  
      Args:
          description (str):
                  A description of what is being saved or loaded.
docstring_summary: Decorator that adds 4 JSON helper methods to a class:
docstring_tokens: Decorator that adds 4 JSON helper methods to a class :
function: def add_json_methods(description=None):
      """
      Decorator that adds 4 JSON helper methods to a class:
  
      - to_json(): Convert to JSON string
      - from_json(): Convert from JSON string
      - save(): Convert to JSON and save to file
      - load(): Load from file and convert from JSON
  
      Args:
          description (str):
                  A description of what is being saved or loaded.
      """
  
      def add_json_methods_impl(cls):
          # JSON methods
  
          def check_decoded(obj):
              if not isinstance(obj, cls):
                  G_LOGGER.critical(
                      "Provided JSON cannot be decoded into a {:}.\n"
                      "Note: JSON was decoded into a {:}:\n{:}".format(cls.__name__, type(obj), obj)
                  )
              return obj
  
          def _to_json_method(self):
              """
              Encode this instance as a JSON object.
  
              Returns:
                  str: A JSON representation of this instance.
              """
              return to_json(self)
  
          def _from_json_method(src):
              return check_decoded(from_json(src))
  
          _from_json_method.__doc__ = """
              Decode a JSON object and create an instance of this class.
  
              Args:
                  src (str):
                          The JSON representation of the object
  
              Returns:
                  {cls}: The decoded instance
  
              Raises:
                  PolygraphyException:
                          If the JSON cannot be decoded to an instance of {cls}
              """.format(
              cls=cls.__name__
          )
  
          cls.to_json = _to_json_method
          cls.from_json = staticmethod(_from_json_method)
  
          # Save/Load methods
  
          def _save_method(self, dest):
              """
              Encode this instance as a JSON object and save it to the specified path
              or file-like object.
  
              Args:
                  dest (Union[str, file-like]):
                        The path or file-like object to write to.
  
              """
              save_json(self, dest, description=description)
  
          def _load_method(src):
              return check_decoded(load_json(src, description=description))
  
          _load_method.__doc__ = """
              Loads an instance of this class from a JSON file.
  
              Args:
                  src (Union[str, file-like]): The path or file-like object to read from.
  
              Returns:
                  {cls}: The decoded instance
  
              Raises:
                  PolygraphyException:
                          If the JSON cannot be decoded to an instance of {cls}
              """.format(
              cls=cls.__name__
          )
  
          cls.save = _save_method
          cls.load = staticmethod(_load_method)
  
          return cls
  
      return add_json_methods_impl
function_tokens: def add_json_methods ( description = None ) : def add_json_methods_impl ( cls ) : # JSON methods def check_decoded ( obj ) : if not isinstance ( obj , cls ) : G_LOGGER . critical ( "Provided JSON cannot be decoded into a {:}.\n" "Note: JSON was decoded into a {:}:\n{:}" . format ( cls . __name__ , type ( obj ) , obj ) ) return obj def _to_json_method ( self ) : """
              Encode this instance as a JSON object.
  
              Returns:
                  str: A JSON representation of this instance.
              """ return to_json ( self ) def _from_json_method ( src ) : return check_decoded ( from_json ( src ) ) _from_json_method . __doc__ = """
              Decode a JSON object and create an instance of this class.
  
              Args:
                  src (str):
                          The JSON representation of the object
  
              Returns:
                  {cls}: The decoded instance
  
              Raises:
                  PolygraphyException:
                          If the JSON cannot be decoded to an instance of {cls}
              """ . format ( cls = cls . __name__ ) cls . to_json = _to_json_method cls . from_json = staticmethod ( _from_json_method ) # Save/Load methods def _save_method ( self , dest ) : """
              Encode this instance as a JSON object and save it to the specified path
              or file-like object.
  
              Args:
                  dest (Union[str, file-like]):
                        The path or file-like object to write to.
  
              """ save_json ( self , dest , description = description ) def _load_method ( src ) : return check_decoded ( load_json ( src , description = description ) ) _load_method . __doc__ = """
              Loads an instance of this class from a JSON file.
  
              Args:
                  src (Union[str, file-like]): The path or file-like object to read from.
  
              Returns:
                  {cls}: The decoded instance
  
              Raises:
                  PolygraphyException:
                          If the JSON cannot be decoded to an instance of {cls}
              """ . format ( cls = cls . __name__ ) cls . save = _save_method cls . load = staticmethod ( _load_method ) return cls return add_json_methods_impl