code: def encode(self, o):
          
          # This is for extremely simple cases and benchmarks.
          if isinstance(o, basestring):
              if isinstance(o, str):
                  _encoding = self.encoding
                  if (_encoding is not None 
                          and not (_encoding == 'utf-8')):
                      o = o.decode(_encoding)
              if self.ensure_ascii:
                  return encode_basestring_ascii(o)
              else:
                  return encode_basestring(o)
          # This doesn't pass the iterator directly to ''.join() because the
          # exceptions aren't as detailed.  The list call should be roughly
          # equivalent to the PySequence_Fast that ''.join() would do.
          chunks = list(self.iterencode(o))
          return ''.join(chunks)
docs: Return a JSON string representation of a Python data structure.
  
          >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
          '{"foo": ["bar", "baz"]}'