class_docstr: JSON encoder for dataset attributes.
class_docstr_tok: ["JSON","encoder","for","dataset","attributes","."]
docstr: Encode the given object as a json-serializable datatype.
docstr_tok: ["Encode","the","given","object","as","a","json-serializable","datatype","."]
code: def _encode(self, obj):
      """Encode the given object as a json-serializable datatype."""
      if isinstance(obj, (bool, np.bool_)):
          # Bool has to be checked first, because it is a subclass of int
          return str(obj).lower()
      elif isinstance(obj, (int, float, str)):
          return obj
      elif isinstance(obj, np.integer):
          return int(obj)
      elif isinstance(obj, np.floating):
          return float(obj)
      elif isinstance(obj, np.void):
          return tuple(obj)
      elif isinstance(obj, np.ndarray):
          return obj.tolist()
      return str(obj)
  
imports: from __future__ import annotations
  import datetime
  import json
  import logging
  from collections import OrderedDict
  import numpy
  import xarray
  from satpy.writers.utils import flatten_dict
label_desc: Use image node_id 2 for calling the AttributeEncoder obj's underlying member method code with example usage: obj._encode(obj) and returns: str, str, obj, int, float, tuple, obj