use `JSONEncodeManager` replace default `output_json` function of Flask-RESTful
    for the advantage of use `JSONEncodeManager`, please see https://github.com/anjianshi/json_encode_manager
430075
def enhance_json_encode(api_instance, extra_settings=None):
    """"""
    api_instance.json_encoder = JSONEncodeManager()

    dumps_settings = {} if extra_settings is None else extra_settings
    dumps_settings['default'] = api_instance.json_encoder
    dumps_settings.setdefault('ensure_ascii', False)

    @api_instance.representation('application/json')
    def output_json(data, code, headers=None):
        if current_app.debug:
            dumps_settings.setdefault('indent', 4)
            dumps_settings.setdefault('sort_keys', True)

        dumped = json.dumps(data, **dumps_settings)
        if 'indent' in dumps_settings:
            dumped += '\n'

        resp = make_response(dumped, code)
        resp.headers.extend(headers or {})
        return resp
249364
def dumps(data, **kwargs):
    """"""

    def _encoder(value):
        if isinstance(value, datetime.datetime):
            return value.isoformat()

        if hasattr(value, "_data"):
            return value._data

        raise TypeError('Could not encode %r' % value)

    return json.dumps(data, default=_encoder, **kwargs)
1020665
def write_json(self, chunk, code=None, headers=None):
        
        assert chunk is not None, 'None cound not be written in write_json'
        self.set_header("Content-Type", "application/json; charset=UTF-8")
        if isinstance(chunk, dict) or isinstance(chunk, list):
            chunk = self.json_encode(chunk)

        # convert chunk to utf8 before `RequestHandler.write()`
        # so that if any error occurs, we can catch and log it
        try:
            chunk = utf8(chunk)
        except Exception:
            app_log.error('chunk encoding error, repr: %s' % repr(chunk))
            raise_exc_info(sys.exc_info())

        self.write(chunk)

        if code:
            self.set_status(code)

        if headers:
            for k, v in headers.items():
                self.set_header(k, v)
590201
def wrap_json_response(func=None, *, encoder=json.JSONEncoder):
    

    if func is None:
        return functools.partial(wrap_json_response, encoder=encoder)

    @functools.wraps(func)
    def wrapper(request, *args, **kwargs):
        response = func(request, *args, **kwargs)

        if "Content-Type" in response.headers and response.headers['Content-Type'] is not None:
            ctype, pdict = parse_header(response.headers.get('Content-Type', ''))
            if ctype == "application/json" and (isinstance(response.body, dict) or isinstance(response.body, list)):
                response.body = json.dumps(response.body, cls=encoder)
        return response

    return wrapper
681445
def _api_convert_output(return_value):
    
    content_type = web.ctx.environ.get('CONTENT_TYPE', 'text/json')

    if "text/json" in content_type:
        web.header('Content-Type', 'text/json; charset=utf-8')
        return json.dumps(return_value)
    if "text/html" in content_type:
        web.header('Content-Type', 'text/html; charset=utf-8')
        dump = yaml.dump(return_value)
        return "<pre>" + web.websafe(dump) + "</pre>"
    if "text/yaml" in content_type or \
                    "text/x-yaml" in content_type or \
                    "application/yaml" in content_type or \
                    "application/x-yaml" in content_type:
        web.header('Content-Type', 'text/yaml; charset=utf-8')
        dump = yaml.dump(return_value)
        return dump
    web.header('Content-Type', 'text/json; charset=utf-8')
    return json.dumps(return_value)
1002143
def pypy_json_encode(value, pretty=False):
    
    global _dealing_with_problem
    if pretty:
        return pretty_json(value)

    try:
        _buffer = UnicodeBuilder(2048)
        _value2json(value, _buffer)
        output = _buffer.build()
        return output
    except Exception as e:
        # THE PRETTY JSON WILL PROVIDE MORE DETAIL ABOUT THE SERIALIZATION CONCERNS
        from mo_logs import Log

        if _dealing_with_problem:
            Log.error("Serialization of JSON problems", e)
        else:
            Log.warning("Serialization of JSON problems", e)
        _dealing_with_problem = True
        try:
            return pretty_json(value)
        except Exception as f:
            Log.error("problem serializing object", f)
        finally:
            _dealing_with_problem = False
571126
function jsonEncoded(gw, callback){
  var buffer = '';
  var readlength = 0;
  var $error = false;
  gw.req.on('data', function (chunk) {
    if (readlength > gw.content.length){$error = true;}
    if (!$error) {
      readlength += chunk.length;
      buffer += chunk.toString('ascii');
    }
  });
  gw.req.on('end', function () {
    if ($error) {
      gw.error(400);
    } else {
      try {
        var params = JSON.parse(buffer);
        gw.content.params = params;
        for(var i=0,k=Object.keys(params),l=k.length;i<l;i++){
          gw.params[k[i]]=params[k[i]];
        }
        callback();
      } catch (error) {
        gw.error(400);
      }
    }
  });
}
91339
def json_data(self, instance, default=None):
        
        value = self.get(instance)
        if value:
            return value.output
        return value
113230
def jsonify(data, pretty=False, **kwargs):
    
    isod = isinstance(data, OrderedDict)
    params = {
        'for_json': True,
        'default': _complex_encode,
    }
    if pretty:
        params['indent'] = 2
        params['sort_keys'] = False if isod else True
    params.update(kwargs)
    try:
        return json.dumps(data, ensure_ascii=False, **params)
    except UnicodeDecodeError:
        return json.dumps(data, **params)
571004
def dump_json(token_dict, dump_path):
    
    if sys.version > '3':
        with open(dump_path, 'w', encoding='utf-8') as output_file:
            json.dump(token_dict, output_file, indent=4)
    else:
        with open(dump_path, 'w') as output_file:
            json.dump(token_dict, output_file, indent=4)
876207
def as_json(data, **kwargs):
    

    if 'sort_keys' not in kwargs:
        kwargs['sort_keys'] = False
    if 'ensure_ascii' not in kwargs:
        kwargs['ensure_ascii'] = False

    data = json.dumps(data, **kwargs)

    return data
475556
def dump_json(self, pretty=True):
        
        # Build template
        t = {}
        t['AWSTemplateFormatVersion'] = '2010-09-09'        
        if self.description is not None:
            t['Description'] = self.description
        self.elements.dump_to_template_obj(self, t)

        return _CustomJSONEncoder(indent=2 if pretty else None,
                                  sort_keys=False).encode(t)
12971
def json_api_call(req_function):
    
    @wraps(req_function)
    def newreq(request, *args, **kwargs):
        outp = req_function(request, *args, **kwargs)
        if issubclass(outp.__class__, HttpResponse):
            return outp
        else:
            return '%s' % json.dumps(outp, cls=LazyEncoder)
    return string_to_response("application/json")(newreq)
1328387
def to_json(self, *args, **kwargs):
        
        return json.dumps(self.serialized, *args, **kwargs)
211320
def _to_json(self, sort_keys=False, indent=4):
        
        return json.dumps(self, sort_keys=sort_keys, indent=indent, cls=CtabAtomBondEncoder)
1144626
def jsonify(obj, status=200, headers=None, refs=False, encoder=JSONEncoder):
    
    if encoder is JSONEncoder:
        data = encoder(refs=refs).encode(obj)
    else:
        data = encoder().encode(obj)
    if 'callback' in request.args:
        cb = request.args.get('callback')
        data = '%s && %s(%s)' % (cb, cb, data)
    return Response(data, headers=headers,
                    status=status,
                    mimetype='application/json')
1184709
def serialize_to_json(self, response_data):
        

        indent = None
        if settings.DEBUG:
            indent = 4

        # Serialize to JSON with Django's encoder: Adds date/time, decimal,
        # and UUID support.
        return json.dumps(response_data, indent=indent, cls=DjangoJSONEncoder)