Wrap a view-like function that returns an object that
        is convertable from json
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)
813064
function (res) {
      var value;
      try {
        value = JSON.parse(res);
        if (typeof value === 'undefined') {
          value = res;
        }
        if (value === 'true') {
          value = true;
        } else if (value === 'false') {
          value = false;
        } else if (parseFloat(value) === value && !angular.isObject(value)) {
          value = parseFloat(value);
        }
      } catch (e) {
        value = res;
      }
      return value;
    }
151748
def _fromJSON(cls, jsonobject):
        
        newInstance = cls(jsonobject[0], jsonobject[1])
        for arrayType, jsonEntry in viewitems(jsonobject[2]):
            arrayEntry = {'dataProcessingRef': jsonEntry['dataProcessingRef'],
                          'params': [tuple(_) for _ in jsonEntry['params']]
                          }
            newInstance.arrayInfo[arrayType] = arrayEntry

        return newInstance
756430
def as_view(url=None, methods=None, view_class=ActionsView, name=None, url_rules=None, **kwargs):
    
    def decorator(f):
        if url is not None:
            f = expose(url, methods=methods)(f)

        clsdict = {"name": name or f.__name__,
                   "actions": getattr(f, "actions", None),
                   "url_rules": url_rules or getattr(f, "urls", None)}

        if isinstance(f, WithActionsDecorator):
            f = f.func
        clsdict['func'] = f

        def constructor(self, **ctorkwargs):
            for k, v in kwargs.items():
                if k not in ctorkwargs or ctorkwargs[k] is None:
                    ctorkwargs[k] = v
            view_class.__init__(self, func=f, **ctorkwargs)

        clsdict["__init__"] = constructor
        return type(f.__name__, (view_class,), clsdict)

    return decorator
698675
function () {
						var args = convertArguments(arguments, luaToJS),
							retval = property.apply(args.shift(), args);

						if (typeof retval == 'object') return jsToLua(retval);
						return [retval];
					}
435943
def from_json(cls, json):
    """"""
    obj = cls(key_range.KeyRange.from_json(json["key_range"]),
              model.QuerySpec.from_json(json["query_spec"]))
    cursor = json["cursor"]
    # lint bug. Class method can access protected fields.
    # pylint: disable=protected-access
    if cursor and json["cursor_object"]:
      obj._cursor = datastore_query.Cursor.from_websafe_string(cursor)
    else:
      obj._cursor = cursor
    return obj
252303
def convert_loaded_json(js):
    
    if not isinstance(js, (Mapping, tuple, list)):
        return try_convert(js)
    try:
        return type(js)(convert_loaded_json(item) for item in js.iteritems())
    except:
        try:
            return type(js)(convert_loaded_json(item) for item in iter(js))
        except:
            return try_convert(js)
481075
def to_json(self, propval, extraneous=False, to_json_func=None):
        
        if self.json_out:
            return self.json_out(propval)
        else:
            if not to_json_func:
                from normalize.record.json import to_json
                to_json_func = to_json
            return to_json_func(propval, extraneous)
455784
function __toJSONSafe(obj, replacer) {
  if (obj !== Object(obj)) return obj; // primitive value
  if (obj._$visited) return undefined;
  replacer = replacer || __safeReplacer;
  if (obj.toJSON) {
    var newObj = obj.toJSON();
    if (newObj !== Object(newObj)) return newObj; // primitive value
    if (newObj !== obj) return __toJSONSafe(newObj, replacer);
    // toJSON returned the object unchanged.
    obj = newObj;
  }
  obj._$visited = true;
  var result;
  if (obj instanceof Array) {
    result = obj.map(function (o) {
      return __toJSONSafe(o, replacer);
    });
  } else if (typeof (obj) === "function") {
    result = undefined;
  } else {
    result = {};
    for (var prop in obj) {
      if (prop === "_$visited") continue;
      var val = obj[prop];
      if (replacer) {
        val = replacer(prop, val);
        if (val === undefined) continue;
      }
      val = __toJSONSafe(val, replacer);
      if (val === undefined) continue;
      result[prop] = val;
    }
  }
  delete obj._$visited;
  return result;
}
1119052
def returns_json(func):
    
    def decorator(*args, **kwargs):
        instance = args[0]
        request = getattr(instance, 'request', None)
        request.response.setHeader("Content-Type", "application/json")
        result = func(*args, **kwargs)
        return json.dumps(result)
    return decorator
569475
def to_json(fn, obj):
    
    with open(fn, 'w') as f:
        json.dump(obj, f, cls=OperatorEncoder, indent=2, ensure_ascii=False)
    return fn
38311
function(bool_return_object) {
                    var obj = { __joii_type: this.__joii__.name };

                    for (var key in this.__joii__.metadata) {
                        var val = this.__joii__.metadata[key];

                        if (val.serializable) {
                            
                            var getter_name = JOII.GenerateGetterName(val);
                            var currentValue = null;
                            if (typeof (this[getter_name]) === 'function') {
                                // use getter if it exists. This allows custom getters to translate the data properly if needed.
                                currentValue = this[getter_name]();
                            } else {
                                currentValue = this[val.name];
                            }

                            if (!val.is_enum && typeof (currentValue) === 'object' && currentValue !== null) {
                                if ('serialize' in currentValue) {
                                    obj[val.name] = currentValue.serialize(true);
                                } else {
                                    obj[val.name] = JOII.Compat.flattenObject(currentValue);
                                }
                            } else {
                                obj[val.name] = currentValue;
                            }
                        }
                    }

                    return obj;
                }
670329
def json_wrap(function, *args, **kwargs):
    ''''''
    try:
        # Some responses have data = None, but they generally signal a
        # successful API call as well.
        response = json.loads(function(*args, **kwargs).content)
        if 'data' in response:
            return response['data'] or True
        else:
            return response
    except Exception as exc:
        raise ClientException(exc)
177600
function wrappedJson(oldJson, inflectorName){
  let args = Array.prototype.slice.call(arguments, 2);
  if (typeof args[0] === 'object') {
    args[0] = transform(args[0], inflectorName);
  } else if (typeof args[1] === 'object') {
    args[1] = transform(args[1], inflectorName);
  }
  return oldJson.apply(this, args);
}
28558
public JSONObject toJSON(ModelView o) throws JSONConverterException {
        ModelViewConverter c = java2json.get(o.getClass());
        if (c == null) {
            throw new JSONConverterException("No converter available for a view with the '" + o.getClass() + "' className");
        }
        return c.toJSON(o);
    }
95141
def json_conversion(obj: Any) -> JSON:
    """"""
    try:
        # numpy isn't an explicit dependency of bowtie
        # so we can't assume it's available
        import numpy as np
        if isinstance(obj, (np.ndarray, np.generic)):
            return obj.tolist()
    except ImportError:
        pass

    try:
        # pandas isn't an explicit dependency of bowtie
        # so we can't assume it's available
        import pandas as pd
        if isinstance(obj, pd.DatetimeIndex):
            return [x.isoformat() for x in obj.to_pydatetime()]
        if isinstance(obj, pd.Index):
            return obj.tolist()
        if isinstance(obj, pd.Series):
            try:
                return [x.isoformat() for x in obj.dt.to_pydatetime()]
            except AttributeError:
                return obj.tolist()
    except ImportError:
        pass

    if isinstance(obj, (datetime, time, date)):
        return obj.isoformat()
    raise TypeError('Not sure how to serialize {} of type {}'.format(obj, type(obj)))
935520
def _converter(data):
    
    handler = REGISTRY.get(data.__class__)
    if handler:
        full_name = '{}.{}'.format(
            data.__class__.__module__,
            data.__class__.__name__)
        return {
            '__class__': full_name,
            '__value__': handler(data),
        }
    raise TypeError(repr(data) + " is not JSON serializable")