Convert to JSON. The given object must be either a valid JSON string or of type {@link JSONAware}, in which
case it is returned directly

@param pValue the value to parse (or to return directly if it is a {@link JSONAware}
@return the resulting value
500311
protected JSONAware toJSON(Object pValue) {
        Class givenClass = pValue.getClass();
        if (JSONAware.class.isAssignableFrom(givenClass)) {
            return (JSONAware) pValue;
        } else {
            try {
                return (JSONAware) new JSONParser().parse(pValue.toString());
            } catch (ParseException e) {
                throw new IllegalArgumentException("Cannot parse JSON " + pValue + ": " + e,e);
            } catch (ClassCastException exp) {
                throw new IllegalArgumentException("Given value " + pValue.toString() +
                                                   " cannot be parsed to JSONAware object: " + exp,exp);
            }
        }
    }
920073
public static JSONObject getObject(JSONValue value) {
        if (value == null)
            return null;
        if (!(value instanceof JSONObject))
            throw new JSONException(NOT_AN_OBJECT);
        return (JSONObject)value;
    }
403065
@Nonnull
  public SoyValueProvider convert(@Nullable Object obj) {
    SoyValueProvider convertedPrimitive = convertCheap(obj);
    if (convertedPrimitive != null) {
      return convertedPrimitive;
    }
    return convertNonPrimitive(obj);
  }
833880
static javax.json.JsonValue map(final JsonValue jsonValue) {
        if (jsonValue instanceof JsonArray)
            return map((JsonArray) jsonValue);
        return map((JsonObject) jsonValue);
    }
488693
public static String toJsonObject(Object... namesAndValues) {

        if (namesAndValues.length % 2 != 0) {
            throw new IllegalArgumentException("number or arguments must be even");
        }
        StringBuilder sb = new StringBuilder("{");

        int count = 0;

        while (true) {
            Object name = namesAndValues[count];
            sb.append("\"").append(name).append("\":");
            if (!(namesAndValues[count + 1] instanceof Number)) {
                if (namesAndValues[count + 1] == null) {
                    sb.append("null");
                } else {
                    sb.append("\"").append(namesAndValues[count + 1].toString()).append("\"");
                }
            } else {
                sb.append(namesAndValues[count + 1].toString());
            }

            if (count < (namesAndValues.length - 2)) {
                sb.append(",");
                count += 2;
            } else {
                sb.append("}");
                break;
            }
        }
        return sb.toString();
    }
413850
public static <P extends ParaObject> String toJSON(P obj) {
		if (obj == null) {
			return "{}";
		}
		try {
			return getJsonWriter().writeValueAsString(obj);
		} catch (Exception e) {
			logger.error(null, e);
		}
		return "{}";
	}
26893
public JSONObject toJson() {

        try {
            JSONObject result = new JSONObject();
            if (null != getStart()) {
                result.put(JsonKey.START, dateToJson(getStart()));
            }
            if (null != getEnd()) {
                result.put(JsonKey.END, dateToJson(getEnd()));
            }
            if (isWholeDay()) {
                result.put(JsonKey.WHOLE_DAY, true);
            }
            JSONObject pattern = patternToJson();
            result.put(JsonKey.PATTERN, pattern);
            SortedSet<Date> exceptions = getExceptions();
            if (!exceptions.isEmpty()) {
                result.put(JsonKey.EXCEPTIONS, datesToJson(exceptions));
            }
            switch (getEndType()) {
                case DATE:
                    result.put(JsonKey.SERIES_ENDDATE, dateToJson(getSeriesEndDate()));
                    break;
                case TIMES:
                    result.put(JsonKey.SERIES_OCCURRENCES, String.valueOf(getOccurrences()));
                    break;
                case SINGLE:
                default:
                    break;
            }
            if (!isCurrentTillEnd()) {
                result.put(JsonKey.CURRENT_TILL_END, false);
            }
            if (null != getParentSeriesId()) {
                result.put(JsonKey.PARENT_SERIES, getParentSeriesId().getStringValue());
            }
            return result;
        } catch (JSONException e) {
            LOG.error("Could not convert Serial date value to JSON.", e);
            return null;
        }
    }
554816
public static <T> T toBean(JSONObject json, Class<T> beanClass) {
		return null == json ? null : json.toBean(beanClass);
	}
627646
public static JSONObject parseObj(Object obj, boolean ignoreNullValue, boolean isOrder) {
		return new JSONObject(obj, ignoreNullValue, isOrder);
	}
135577
@Override
    public String toJSON() {
        final ObjectMapper mapper = buildObjectMapperForSerialization();
        try {
            return mapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
            throw new IllegalStateException("Object cannot be parsed as JSON.", e);
        }
    }
268969
@JsonValue
	public Object toJsonValue() {
		if (definition != null)
			return definition;
		if (reference != null)
			return reference;
		if (_null != null)
			return _null;
		return null;
	}
548419
public JSONObject toJSON() throws JSONException {
        JSONObject json = new JSONObject();

        json.put(JSON_TYPE, this.getType());

        return json;
    }
833852
@Override
    Object asJSON() {
        final List<Object> json = new ArrayList<>();
        if (fromAlias != null) { json.add("." + fromAlias + "." + keyPath); }
        else { json.add("." + keyPath); }
        return json;
    }
1186090
def fromJSON(jsonValue):
        """"""
        jd = json.loads(jsonValue)
        features = []
        if 'fields' in jd:
            fields = jd['fields']
        else:
            fields = {'fields':[]}
        if 'features' in jd:
            for feat in jd['features']:
                wkid = None
                spatialReference =None
                if 'spatialReference' in jd:
                    spatialReference = jd['spatialReference']
                    if 'wkid' in jd['spatialReference']:
                        wkid = jd['spatialReference']['wkid']
                    elif 'latestWkid' in jd['spatialReference']: # kept for compatibility
                        wkid = jd['spatialReference']['latestWkid']
                features.append(Feature(json_string=feat, wkid=wkid, spatialReference=spatialReference))
        return FeatureSet(fields,
                          features,
                          hasZ=jd['hasZ'] if 'hasZ' in jd else False,
                          hasM=jd['hasM'] if 'hasM' in jd else False,
                          geometryType=jd['geometryType'] if 'geometryType' in jd else None,
                          objectIdFieldName=jd['objectIdFieldName'] if 'objectIdFieldName' in jd else None,
                          globalIdFieldName=jd['globalIdFieldName'] if 'globalIdFieldName' in jd else None,
                          displayFieldName=jd['displayFieldName'] if 'displayFieldName' in jd else None,
                          spatialReference=jd['spatialReference'] if 'spatialReference' in jd else None)
104698
@SuppressWarnings("unchecked")
	public JSONObject toJSONObject() {
		final JSONObject activity = new JSONObject();

		// parse time stamp
		activity.put("published",
				dateFormatter.format(new Date(this.timestamp)));

		// TODO: check performance
		// parse user
		// final Map<String, Object> user = this.creator.toActorJSON();
		// activity.put("actor", user);

		// parse verb:read
		activity.put("verb", "read");

		// parse object
		final Map<String, Object> object = this.toObjectJSON();
		activity.put("object", object);

		return activity;
	}
454973
public JSONObject toJson() {
        JSONObject ret = new JSONObject();
        ret.put("url",url);
        if (user != null) {
            ret.put("user",user);
            ret.put("password",password);
        }
        return ret;
    }
1033219
public JSONObject toJSON() {
        JSONObject ret = super.toJSON();
        if (arguments != null && arguments.size() > 0) {
            ret.put("arguments", arguments);
        }
        ret.put("operation", operation);
        return ret;
    }