docstr: Given a message object to be passed to Perspective, serialize it
  into a string using `DateTimeEncoder` and `allow_nan=False`.
  
  If an Exception occurs in serialization, catch the Exception and
  return an error message using `self._make_error_message`.
  
  Args:
      message (:obj:`dict`) a serializable message to be passed to
          Perspective.
docstr_tok: ["Given","a","message","object","to","be","passed","to","Perspective",",","serialize","it","into","a","string","using","`","DateTimeEncoder","`","and","`","allow_nan=False","`",".","If","an","Exception","occurs","in","serialization",",","catch","the","Exception","and","return","an","error","message","using","`","self._make_error_message","`",".","Args",":","message","(",":","obj",":","`","dict","`",")","a","serializable","message","to","be","passed","to","Perspective","."]
code: def _message_to_json(self, id, message):
      """Given a message object to be passed to Perspective, serialize it
      into a string using `DateTimeEncoder` and `allow_nan=False`.
  
      If an Exception occurs in serialization, catch the Exception and
      return an error message using `self._make_error_message`.
  
      Args:
          message (:obj:`dict`) a serializable message to be passed to
              Perspective.
      """
      try:
          return json.dumps(
              message, allow_nan=False, cls=DateTimeEncoder
          )
      except ValueError as error:
          error_string = str(error)
  
          # Augment the default error message when invalid values are
          # detected, i.e. `NaN`
          if (
              error_string
              == "Out of range float values are not JSON compliant"
          ):
              error_string = "Cannot serialize `NaN`, `Infinity` or `-Infinity` to JSON."
  
          error_message = self._make_error_message(
              id, "JSON serialization error: {}".format(error_string)
          )
  
          logging.warning(error_message["error"])
          return json.dumps(error_message)
  
imports: import datetime
  import json
  import logging
  from collections import deque
  from functools import partial
  from ..core.exception import PerspectiveError
  from ..table import PerspectiveCppError, Table
  from ..table._callback_cache import _PerspectiveCallBackCache
  from ..table._date_validator import _PerspectiveDateValidator
label_desc: Use image node_id 12 for calling the _PerspectiveManagerInternal obj's underlying member method code with example usage: obj._message_to_json(id, message) and returns: json, json