'Return a JSON string representation of a Python data structure.
>>> from simplejson import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
\'{"foo": ["bar", "baz"]}\''

def encode(self, o):

    if isinstance(o, binary_type):
        _encoding = self.encoding
        if ((_encoding is not None) and (not (_encoding == 'utf-8'))):
            o = o.decode(_encoding)
    if isinstance(o, string_types):
        if self.ensure_ascii:
            return encode_basestring_ascii(o)
        else:
            return encode_basestring(o)
    chunks = self.iterencode(o, _one_shot=True)
    if (not isinstance(chunks, (list, tuple))):
        chunks = list(chunks)
    if self.ensure_ascii:
        return ''.join(chunks)
    else:
        return u''.join(chunks)
