code: def json_encode(obj):
      
      try:
          return json_encode.encoder.encode(obj)
      except AttributeError:
          json_encode.encoder = DjangoJSONEncoder(default=six.text_type)
          return json_encode(obj)
docs: Encode a python object to json