Creates a JSONArray.<br>
Inspects the object type to call the correct JSONArray factory method.
Accepts JSON formatted strings, arrays and Collections.

@param object
@throws JSONException if the object can not be converted to a proper
JSONArray.
501709
public static JSONArray fromObject( Object object, JsonConfig jsonConfig ) {
      if( object instanceof JSONString ){
         return _fromJSONString( (JSONString) object, jsonConfig );
      }else if( object instanceof JSONArray ){
         return _fromJSONArray( (JSONArray) object, jsonConfig );
      }else if( object instanceof Collection ){
         return _fromCollection( (Collection) object, jsonConfig );
      }else if( object instanceof JSONTokener ){
         return _fromJSONTokener( (JSONTokener) object, jsonConfig );
      }else if( object instanceof String ){
         return _fromString( (String) object, jsonConfig );
      }else if( object != null && object.getClass()
            .isArray() ){
         Class type = object.getClass()
               .getComponentType();  
         if( !type.isPrimitive() ){
            return _fromArray( (Object[]) object, jsonConfig );
         }else{
            if( type == Boolean.TYPE ){
               return _fromArray( (boolean[]) object, jsonConfig );
            }else if( type == Byte.TYPE ){
               return _fromArray( (byte[]) object, jsonConfig );
            }else if( type == Short.TYPE ){
               return _fromArray( (short[]) object, jsonConfig );
            }else if( type == Integer.TYPE ){
               return _fromArray( (int[]) object, jsonConfig );
            }else if( type == Long.TYPE ){
               return _fromArray( (long[]) object, jsonConfig );
            }else if( type == Float.TYPE ){
               return _fromArray( (float[]) object, jsonConfig );
            }else if( type == Double.TYPE ){
               return _fromArray( (double[]) object, jsonConfig );
            }else if( type == Character.TYPE ){
               return _fromArray( (char[]) object, jsonConfig );
            }else{
               throw new JSONException( "Unsupported type" );
            }
         }
      }else if( JSONUtils.isBoolean( object ) || JSONUtils.isFunction( object )
            || JSONUtils.isNumber( object ) || JSONUtils.isNull( object )
            || JSONUtils.isString( object ) || object instanceof JSON ){
         fireArrayStartEvent( jsonConfig );
         JSONArray jsonArray = new JSONArray().element( object, jsonConfig );
         fireElementAddedEvent( 0, jsonArray.get( 0 ), jsonConfig );
         fireArrayStartEvent( jsonConfig );
         return jsonArray;
      }else if( JSONUtils.isObject( object ) ){
         fireArrayStartEvent( jsonConfig );
         JSONArray jsonArray = new JSONArray().element( JSONObject.fromObject( object, jsonConfig ) );
         fireElementAddedEvent( 0, jsonArray.get( 0 ), jsonConfig );
         fireArrayStartEvent( jsonConfig );
         return jsonArray;
      }else{
         throw new JSONException( "Unsupported type" );
      }
   }
579385
public static JSONObject getJSONObject(HttpPost request, Integer method, HashMap<String, String> params) throws JSONException {
        switch (method) {
        case METHOD_PUT:
        case METHOD_DELETE:
        case METHOD_POST:
            return doPostRequest(request, params);
        default:
            throw new RuntimeException("Wrong http method requested");
        }
    }
976680
public static void saveJson(File json, Object object) throws IOException {
        objectMapper.writer().writeValue(json, object);
    }
298279
@SuppressWarnings("unchecked")
	@Override
	public <E> String serialize(E object) {
		if (object == null)
			return null;

		SegmentedStringWriter source = new SegmentedStringWriter(buffer.get());
		try (SerializerWrapper serializer = createSerializer(source)) {
			mapperFor((Class<E>) object.getClass()).serialize(this, serializer, object);
		} catch (Exception e) {
			e.printStackTrace();
			throw new KriptonRuntimeException(e);
		}

		return source.getAndClear();

	}
786281
public static JSONArray fetchDirectoryObjectJSONArray(JSONObject jsonObject) throws Exception {
        JSONArray jsonArray = new JSONArray();
        jsonArray = jsonObject.optJSONObject("responseMsg").optJSONArray("value");
        return jsonArray;
    }
1022659
@Override
	public String toJson(Object obj) {
		try {
			String json;
			if (obj == null) {
				json = null;
			}
			else {
				json = mapper.writeValueAsString(obj);
			}
			return json;
		}
		catch (Exception e) {
			throw new JsonException(e.getMessage(), e);
		}
	}
795787
public final void addObject(Object object) {
        if (object instanceof Iterable) {
            // Iterable
            for (Object o : (Iterable<?>) object) {
                objects.add(o);
            }
        } else if (object.getClass().isArray()) {
            // Array
            for (Object o : (Object[]) object) {
                objects.add(o);
            }
        } else {
            // Single object
            objects.add(object);
        }
    }
868864
public JSONObject getJson() throws JSONException {
        JSONObject json = create();
        if (value != null)
            json.put("value", value);
        if (label != null)
            json.put("label", label);
        if (type != null)
            json.put("type", type);
        if (display != null)
            json.put("display", display.toString());
        if (sequence != 0)
            json.put("sequence", sequence);
        if (indexKey != null)
            json.put("indexKey", indexKey);
        return json;
    }
496077
public void fromJson(JSONObject json) {
        super.fromJson(json);
        if (json.containsKey(CHANGE)) {
            change = new Change(json.getJSONObject(CHANGE));
        }
        if (json.containsKey(PATCH_SET)) {
            patchSet = new PatchSet(json.getJSONObject(PATCH_SET));
        } else if (json.containsKey(PATCHSET)) {
            patchSet = new PatchSet(json.getJSONObject(PATCHSET));
        }
    }
147455
public static byte[] serialize(Object object) {
    	try {
			return serializer.serialize(object);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
    }
1168357
public JsonWriter write(Object object) throws IOException {
        if (object == null) {
            writeNull();
        } else if (object instanceof String
                || object instanceof Date) {
            writeValue(object.toString());
        } else if (object instanceof Boolean) {
            writeValue((Boolean)object);
        } else if (object instanceof Number) {
            writeValue((Number)object);
        } else if (object instanceof Parameters) {
            openCurlyBracket();

            Map<String, ParameterValue> params = ((Parameters)object).getParameterValueMap();
            Iterator<ParameterValue> it = params.values().iterator();
            while (it.hasNext()) {
                Parameter p = it.next();
                String name = p.getName();
                Object value = p.getValue();
                checkCircularReference(object, value);

                writeName(name);
                write(value);
                if (it.hasNext()) {
                    writeComma();
                }
            }

            closeCurlyBracket();
        } else if (object instanceof Map<?, ?>) {
            openCurlyBracket();

            @SuppressWarnings("unchecked")
            Iterator<Map.Entry<Object, Object>> it = ((Map<Object, Object>)object).entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<Object, Object> entry = it.next();
                String name = entry.getKey().toString();
                Object value = entry.getValue();
                checkCircularReference(object, value);

                writeName(name);
                write(value);
                if (it.hasNext()) {
                    writeComma();
                }
            }

            closeCurlyBracket();
        } else if (object instanceof Collection<?>) {
            openSquareBracket();

            @SuppressWarnings("unchecked")
            Iterator<Object> it = ((Collection<Object>)object).iterator();
            while (it.hasNext()) {
                Object value = it.next();
                checkCircularReference(object, value);

                write(value);
                if (it.hasNext()) {
                    writeComma();
                }
            }

            closeSquareBracket();
        } else if (object.getClass().isArray()) {
            openSquareBracket();

            int len = Array.getLength(object);
            for (int i = 0; i < len; i++) {
                Object value = Array.get(object, i);
                checkCircularReference(object, value);

                if (i > 0) {
                    writeComma();
                }
                write(value);
            }

            closeSquareBracket();
        } else {
            String[] readablePropertyNames = BeanUtils.getReadablePropertyNamesWithoutNonSerializable(object);
            if (readablePropertyNames != null && readablePropertyNames.length > 0) {
                openCurlyBracket();

                for (int i = 0; i < readablePropertyNames.length; i++) {
                    Object value;
                    try {
                        value = BeanUtils.getProperty(object, readablePropertyNames[i]);
                    } catch (InvocationTargetException e) {
                        throw new IOException(e);
                    }
                    checkCircularReference(object, value);

                    writeName(readablePropertyNames[i]);
                    write(value);
                    if (i < (readablePropertyNames.length - 1)) {
                        writeComma();
                    }
                }

                closeCurlyBracket();
            } else {
                writeValue(object.toString());
            }
        }
        return this;
    }
1351766
private void buildLog() throws JSONException {
        logs = new JSONObject();
        List<String> list = Log.getReportedEntries();
        if (list != null) {
            logs.put("numberOfEntry", list.size());
            JSONArray array = new JSONArray();
            for (String s : list) {
                array.put(s);
            }
            logs.put("log", array);
        }
    }
784237
function JsonArray(arr) {
    if (!(this instanceof JsonArray)) {
        return new JsonArray(arr);
    }
    Array.call(this);
    var i = -1, l = arr.length;
    while (++i < l) {
        this.push(arr[i]);
    }
}
993026
public static EscEvents create(final JsonArray jsonArray) {
        final List<EscEvent> events = new ArrayList<>();
        for (final JsonValue jsonValue : jsonArray) {
            if (jsonValue.getValueType() != JsonValue.ValueType.OBJECT) {
                throw new IllegalArgumentException(
                        "All elements in the JSON array must be an JsonObject, but was: " + jsonValue.getValueType());
            }
            events.add(EscEvent.create((JsonObject) jsonValue));
        }
        return new EscEvents(events);
    }
1067208
public static String toJSONString(Object object) {
        if (object == null) {
            return null;
        }
        return JSONObject.toJSONString(object);
    }
11184
private void loadEntireJsonObject(JSONObject json) throws JSONException {
    Iterator<?> it = json.keys();
    while (it.hasNext()) {
      // This key is something like core-site.xml or hdfs-site.xml
      Object obj = it.next();
      if (!(obj instanceof String)) {
        LOG.warn("Object not instance of string : " + obj + " skipping");
        continue;
      }
      String key = (String) obj;
      JSONObject partition = json.getJSONObject(key);
      loadJsonResource(partition, properties, key);
    }
  }
730248
public Serializer writeObject(JSONObject object) throws IOException {
        if (null == object) return writeNull();

        // write header
        writeRawString("{");
        indentPush();

        Iterator iter = null;
        if (object instanceof OrderedJSONObject)
        {
            iter = ((OrderedJSONObject)object).getOrder();
        }
        else
        {
            List propertyNames = getPropertyNames(object);
            iter = propertyNames.iterator();
        }

        while ( iter.hasNext() )
        {
            Object key = iter.next();
            if (!(key instanceof String)) throw new IOException("attempting to serialize object with an invalid property name: '" + key + "'" );

            Object value = object.get(key);
            if (!JSONObject.isValidObject(value)) throw new IOException("attempting to serialize object with an invalid property value: '" + value + "'");

            newLine();
            indent();
            writeString((String)key);
            writeRawString(":");
            space();
            write(value);

            if (iter.hasNext()) writeRawString(",");
        }

        // write trailer
        indentPop();
        newLine();
        indent();
        writeRawString("}");

        return this;
    }