Wraps the given object if to JsonXXX object.
353772
public static JsonElement wrap(Object o) throws JsonException {
        if (o == null) {
            //null value means not specified i.e.-> no valued will be mapped
            //Json.null is specific value
            return null;
        }
        if (o instanceof JsonElement) {
            return (JsonElement) o;
        }
        if (o instanceof ElementWrapper) {
            return ((ElementWrapper) o).getJson();
        }
        if (o instanceof Collection) {
            return new JsonArray((Collection) o);
        } else if (o.getClass().isArray()) {
            return new JsonArray(o);
        }
        if (o instanceof Map) {
            return new JsonObject((Map) o);
        }
        if (o instanceof Boolean) {
            return new JsonBoolean((Boolean) o);
        }
        if (o instanceof Number) {
            return new JsonNumber((Number) o);
        }
        if (o instanceof String) {
            return new JsonString((String) o);
        }
        if (o instanceof Character) {
            return new JsonString(Character.toString((Character) o));
        }
        if (o instanceof ByteBuffer) {
            return new JsonString(((ByteBuffer) o).asCharBuffer().toString());
        }

        return new JsonString(o.toString());
    }
245503
def object_to_json(obj):
    """"""
    if isinstance(obj, (datetime.datetime, datetime.date, datetime.time)):
        return obj.isoformat()
    return str(obj)
431923
def to_json(value, **kwargs):
        """"""
        if isinstance(value, HasProperties):
            return value.serialize(**kwargs)
        try:
            return json.loads(json.dumps(value))
        except TypeError:
            raise TypeError(
                "Cannot convert type {} to JSON without calling 'serialize' "
                "on an instance of Instance Property and registering a custom "
                "serializer".format(value.__class__.__name__)
            )
539798
def value2json(obj, pretty=False, sort_keys=False, keep_whitespace=True):
    
    if FIND_LOOPS:
        obj = scrub(obj, scrub_text=_keep_whitespace if keep_whitespace else _trim_whitespace())
    try:
        json = json_encoder(obj, pretty=pretty)
        if json == None:
            Log.note(str(type(obj)) + " is not valid{{type}}JSON", type=" (pretty) " if pretty else " ")
            Log.error("Not valid JSON: " + str(obj) + " of type " + str(type(obj)))
        return json
    except Exception as e:
        e = Except.wrap(e)
        try:
            json = pypy_json_encode(obj)
            return json
        except Exception:
            pass
        Log.error("Can not encode into JSON: {{value}}", value=text_type(repr(obj)), cause=e)
957930
def _encode(cls, value):
        """"""

        value = json.dumps(value)
        return cls._ENC_RE.sub(lambda x: '%%%2x' % ord(x.group(0)), value)
9772
def _json_convert(obj, json_options=DEFAULT_JSON_OPTIONS):
    
    if hasattr(obj, 'iteritems') or hasattr(obj, 'items'):  # PY3 support
        return SON(((k, _json_convert(v, json_options))
                    for k, v in iteritems(obj)))
    elif hasattr(obj, '__iter__') and not isinstance(obj, (text_type, bytes)):
        return list((_json_convert(v, json_options) for v in obj))
    try:
        return default(obj, json_options)
    except TypeError:
        return obj
642514
def _to_json_default(obj):
    
    # Datetime
    if isinstance(obj, datetime.datetime):
        return obj.isoformat()

    # UUID
    if isinstance(obj, uuid.UUID):
        return str(obj)

    # numpy
    if hasattr(obj, 'item'):
        return obj.item()

    # # Enum
    # if hasattr(obj, 'value'):
    #     return obj.value

    try:
        return obj.id
    except Exception:
        raise TypeError('{obj} is not JSON serializable'.format(obj=repr(obj)))
1175935
function ( obj ) {
            var n;
            for ( n in obj ) {
                if ( _dom[n] ) {
                    throw new Error( '[ixBand] Extend Error : ixBand에 "' + n + '" Method가 이미 존재합니다.' );
                } else {
                    _dom[n] = obj[n];
                }
            }
        }
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)
460260
def json_friendly(obj):
    """"""
    converted = True
    typename = get_full_typename(obj)

    if is_tf_tensor_typename(typename):
        obj = obj.eval()
    elif is_pytorch_tensor_typename(typename):
        try:
            if obj.requires_grad:
                obj = obj.detach()
        except AttributeError:
            pass  # before 0.4 is only present on variables

        try:
            obj = obj.data
        except RuntimeError:
            pass  # happens for Tensors before 0.4

        if obj.size():
            obj = obj.numpy()
        else:
            return obj.item(), True

    if np and isinstance(obj, np.ndarray):
        if obj.size == 1:
            obj = obj.flatten()[0]
        elif obj.size <= 32:
            obj = obj.tolist()
    elif np and isinstance(obj, np.generic):
        obj = obj.item()
    elif isinstance(obj, bytes):
        obj = obj.decode('utf-8')
    elif isinstance(obj, (datetime, date)):
        obj = obj.isoformat()
    else:
        converted = False
    if getsizeof(obj) > VALUE_BYTES_LIMIT:
        logger.warning("Object %s is %i bytes", obj, getsizeof(obj))

    return obj, converted
1061785
def _unjsonify(x, isattributes=False):
    """"""
    if isattributes:
        obj = json.loads(x)
        return dict_class(obj)
    return json.loads(x)
969991
private Object replaceObject(Object value)
  {
    try {
      return _method.invoke(value);
    } catch (Exception e) {
      throw new JsonException(_method.getDeclaringClass().getSimpleName() + ": " + e,
                              e);
    }
  }
934893
def _json_safe(cls, value):
        """"""
        # Date
        if type(value) == date:
            return str(value)

        # Datetime
        elif type(value) == datetime:
            return value.strftime('%Y-%m-%d %H:%M:%S')

        # Object Id
        elif isinstance(value, ObjectId):
            return str(value)

        # Frame
        elif isinstance(value, _BaseFrame):
            return value.to_json_type()

        # Lists
        elif isinstance(value, (list, tuple)):
            return [cls._json_safe(v) for v in value]

        # Dictionaries
        elif isinstance(value, dict):
            return {k:cls._json_safe(v) for k, v in value.items()}

        return value
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);
}
1317236
private static Optional<ICondition> asAllOf( JsonObject json)
    {
    return
      json.containsKey( ALL_OF_KEY)
      ? Optional.of( new AllOf( toConditions( json.getJsonArray( ALL_OF_KEY))))
      : Optional.empty();
    }
1169094
public JsonObject getJsonObject(int index) throws JsonException {
        JsonElement el = get(index);
        if (!el.isJsonObject()) {
            throw Util.typeMismatch(index, el, "JsonObject");
        }
        return el.asJsonObject();
    }
1268107
private static Object convert(Object x) throws JSONException {
    if (x instanceof JSONObject) {
      JSONObject jsonObject = (JSONObject) x;
      String[] names = JSONObject.getNames(jsonObject);
      if (names == null || names.length == 0) {
        return new HashMap<>(0);
      }
      HashMap<String, Object> map = new HashMap<>(names.length);
      for (String name : names) {
        Object value = jsonObject.get(name);
        map.put(name, convert(value));
      }
      return map;
    } else if (x instanceof JSONArray) {
      JSONArray jsonArray = (JSONArray) x;
      int length = jsonArray.length();
      List<Object> list = new ArrayList<>(length);
      for (int i = 0; i < length; i++) {
        list.add(convert(jsonArray.get(i)));
      }
      return list;
    } else {
      return x;
    }
  }