Formats the object's attributes as GeoJSON.

@return A GeoJSON formatted {@link JSONObject}

@throws JSONException
548419
public JSONObject toJSON() throws JSONException {
        JSONObject json = new JSONObject();

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

        return json;
    }
542684
public function toGeoJson() {
        $Context = $this->_context;


        //If is a invalid object
        if (null === $Context) {
            return $Context;
        }


        //If is not an array(query response) and  is a object
        if (!is_array($Context)) {
            //Check if is a valid entity object
            if (is_object($Context) && isset($Context->id) && isset($Context->type)) {
                $Context = [$Context];
            } else {
                return null;
            }
        }

        $geoJson = (object) ["type" => "FeatureCollection", "features" => []];

        //Build FeatureCollection
//        $countContext = count($Context);
        foreach ($Context as $Entity) { //0.0080490112304688 Seconds
//        for ($i = 0; $i < $countContext; $i++) { //0.025826215744019 Seconds
//            $Entity = $Context[$i];

            if (!(isset($Entity->id) && isset($Entity->type))) {
                continue;
            }
            
            $Feature = (object) ["type" => "Feature", "properties" => ['__metadata'=>[]], "geometry" => null];

            $entityType = null;
            $entityID = null;
            //Roll-out all properties of this feature
            foreach ($Entity as $key => $attr) {
                switch ($key) {
                    case "id":
                        $entityID = $attr;
                        $Feature->properties[$key] = $attr;
                        break;
                    case "type":
                        $entityType = $attr;
                        $Feature->properties[$key] = $attr;
                        break;
                    default:
                        switch ($attr->type) {
                            case "geo:json":
                                $Feature->geometry = $attr->value;
                                $Feature->geometry->type = ucfirst(strtolower($Feature->geometry->type)); //Normalization of geoJson geometry type name.
                                if (isset($attr->metadata) && !empty((array) $attr->metadata)) {
                                    $Feature->properties['geo_metadata'] = $attr->metadata;
                                }
                                break;
                            case "geo:point":
                                $coords = array_reverse(explode(",", $attr->value)); //Change WGS84 Lat Long to Long Lat as GeoJson specifications.

                                array_filter($coords, function($coord) {
                                    return floatval(trim($coord));
                                });

                                $Feature->geometry = (object) [
                                            "type" => "Point",
                                            "coordinates" => $coords
                                ];

                                if (isset($attr->metadata) && !empty((array) $attr->metadata)) {
                                    $Feature->properties['geo_metadata'] = $attr->metadata;
                                }
                                break;
                            case "geo:box":
                                $x = array_reverse(explode(",", $attr->value[0])); //Change WGS84 Lat Long to Long Lat as GeoJson specifications.
                                $y = array_reverse(explode(",", $attr->value[1])); //Change WGS84 Lat Long to Long Lat as GeoJson specifications.
                                //Convert boundary box to polygon using WKT  format POLYGON(x1 y1, x1 y2, x2 y2, x2 y1, x1 y1)
                                $coords = [
                                    [$x[0], $y[0]], //x1 y1
                                    [$x[0], $y[1]], //x1 y2
                                    [$x[1], $y[1]], //x2 y2
                                    [$x[0], $y[0]], //x2 y1                                      
                                    [$x[0], $y[0]] //x1 y1
                                ];

                                $Feature->geometry = (object) [
                                            "type" => "Polygon",
                                            "coordinates" => $coords
                                ];

                                if (isset($attr->metadata) && !empty((array) $attr->metadata)) {
                                    $Feature->properties['geo_metadata'] = $attr->metadata;
                                }
                                break;
                            case "geo:polygon":
                            case "geo:line":
                                //Transform Value Pairs to Polygon/Line Coords
                                $coords = array_filter($attr->value, function($rawvalue) {
                                    $coords = array_reverse(explode(",", $rawvalue)); //Change WGS84 Lat Long to Long Lat as GeoJson specifications.
                                    array_filter($coords, function($coord) {
                                        return floatval(trim($coord));
                                    });
                                    return $coords;
                                });

                                $Feature->geometry = (object) [
                                            "type" => ($attr->type == "geo:polygon") ? "Polygon" : "LineString",
                                            "coordinates" => $coords
                                ];

                                if (isset($attr->metadata) && !empty((array) $attr->metadata)) {
                                    $Feature->properties['geo_metadata'] = $attr->metadata;
                                }
                                break;
                            default:
                                $Feature->properties[$key] = $attr->value;
                                if (isset($attr->metadata) && !empty((array) $attr->metadata)) {
                                    $Feature->properties['__metadata'][$key] = $attr->metadata;
                                }

                                //Add type to metadata
                                if(isset($attr->type)){
                                    if(!isset($Feature->properties['__metadata'][$key])){
                                        $Feature->properties['__metadata'][$key] = [];
                                    }

                                    $Feature->properties['__metadata'][$key]['type'] = $attr->type;
                                }

                                break;
                        }
                        break;
                }
            }
            
            $Feature->id = "{$entityType}-{$entityID}";

            //Finally if this context have a valid geometry append to feature collection
            if ($Feature->geometry != null) {
                $Feature->properties = (object) $Feature->properties;
                array_push($geoJson->features, $Feature);
            }
        }

        return $geoJson;
    }
513143
@NonNull
    public JSONObject toJson() throws JSONException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(KEY_COMPONENT_NAME, (mComponentName != null) ? mComponentName.flattenToShortString() : null);
        jsonObject.put(KEY_IMAGE_URI, (mImageUri != null) ? mImageUri.toString() : null);
        jsonObject.put(KEY_TITLE, mTitle);
        jsonObject.put(KEY_BYLINE, mByline);
        jsonObject.put(KEY_ATTRIBUTION, mAttribution);
        jsonObject.put(KEY_TOKEN, mToken);
        jsonObject.put(KEY_VIEW_INTENT, (mViewIntent != null)
                ? mViewIntent.toUri(Intent.URI_INTENT_SCHEME) : null);
        jsonObject.put(KEY_META_FONT, mMetaFont);
        jsonObject.put(KEY_DATE_ADDED, mDateAdded != null ? mDateAdded.getTime() : 0);
        return jsonObject;
    }
476086
private Map<String, Object> jsonRepresentation() {
        final Map<String, Object> json = new HashMap<>(getProperties());
        json.put(META_PROP_TYPE, TYPE_BLOB);
        if (blobDigest != null) {
            json.put(PROP_DIGEST, blobDigest);
        }
        else {
            json.put(META_PROP_DATA, getContent());
        }
        return json;
    }
285800
public JsonNode toJsonObject() {
		ObjectNode node = new ObjectMapper().createObjectNode();
		if (id != null) {
			node.put("id", id);
		}
		for (DataColumn column : columns) {
			String value = content.get(column);
			if (value != null) {
				node.put(column.getCode(), value);
			} else {
				node.put(column.getCode(), "");
			}
		}
		return node;
	}
509958
public String toJson() {
        try {
            return JsonSerializer.toString(this);
        } catch (Exception e) {
            String message = String.format("Unformateable JSON search: %s", e.getMessage());
            Log.error(e, message);
            throw new IllegalArgumentException(message, e);
        }
    }
1187338
public String toJSONString() {
        if (context.isPretty()) {
            return JSON.toJSONStringWithDateFormat(this, Constant.DATE_SERIALIZE_FORMAT, SerializerFeature.PrettyFormat);
        } else {
            return JSONObject.toJSONStringWithDateFormat(this, Constant.DATE_SERIALIZE_FORMAT);
        }
    }
894736
@Override
	public String toFormatJson(Object obj) {
		if (obj == null) {
			return null;
		}
		try {
			return writer.writeValueAsString(obj);
		}
		catch (Exception e) {
			throw new JsonException(e.getMessage(), e);
		}

	}
622268
public JSONObject getJson() throws JSONException {
        JSONObject json = create();
        json.put("id", getLogicalId());
        json.put("to", "A" + toId);
        if (completionCode != null)
            json.put("resultCode", completionCode);
        if (eventType != null)
            json.put("event", EventType.getEventTypeName(eventType));
        if (attributes != null && ! attributes.isEmpty())
            json.put("attributes", Attribute.getAttributesJson(attributes));
        return json;
    }
556680
public JSONObject getJson() throws JSONException {
        JSONObject json = create();
        json.put("implementorClass", implementorClass);
        if (category != null)
            json.put("category", category);
        if (label != null)
            json.put("label", label);
        if (icon != null)
            json.put("icon", icon);
        if (pagelet != null)
            json.put("pagelet", pagelet);
        if (hidden)
            json.put("hidden", true);
        return json;
    }
620841
protected Map jsonMap() {
        checkJsonContentType();
        try {
            return JsonHelper.toMap(getRequestString());
        } catch (IOException e) {
            throw new WebException(e);
        }
    }
83266
public String toJSON() {
        JSONBuilder jb = new JSONBuilder(estimateMaximumBytes()).append('{');
        appendParams(jb).append(',');
        appendTables(jb);
        jb.append('}');

        return jb.toString();
    }
854219
public String toJson(Object o) {
		try {
			String json = objectMapper.writeValueAsString(o);
			LOG.debug(json);
			return json;
		} catch (Exception e) {
			throw Exceptions.propagate(e);
		}
	}
1085620
public static String formatJson(String json) {
    assertInitialization();
    return XLog.sLogConfiguration.jsonFormatter.format(json);
  }
654249
@Override
    public JSONObject toJSONObject()
    {
        final JSONObject object = new JSONObject();

        object.put("type", new JSONString(getNodeType().getValue()));

        if (hasMetaData())
        {
            final MetaData meta = getMetaData();

            if (false == meta.isEmpty())
            {
                object.put("meta", new JSONObject(meta.getJSO()));
            }
        }
        object.put("attributes", new JSONObject(getAttributes().getJSO()));

        final NFastArrayList<IPrimitive<?>> list = getChildNodes();

        final JSONArray children = new JSONArray();

        if (null != list)
        {
            final int size = list.size();

            for (int i = 0; i < size; i++)
            {
                final IPrimitive<?> prim = list.get(i);

                if (null != prim)
                {
                    final JSONObject make = prim.toJSONObject();

                    if (null != make)
                    {
                        children.set(children.size(), make);
                    }
                }
            }
        }
        object.put("children", children);

        object.put("storage", getStorageEngine().toJSONObject());

        return object;
    }
130039
public JsonObject getJsonObject() {

        JsonObject obj = new JsonObject();
        obj.add("field", this.field);

        obj.add("value", this.value);

        return obj;
    }
337810
public static JSONObject toJSONObject(java.util.Properties properties) throws JSONException {
        // can't use the new constructor for Android support
        // JSONObject jo = new JSONObject(properties == null ? 0 : properties.size());
        JSONObject jo = new JSONObject();
        if (properties != null && !properties.isEmpty()) {
            Enumeration<?> enumProperties = properties.propertyNames();
            while(enumProperties.hasMoreElements()) {
                String name = (String)enumProperties.nextElement();
                jo.put(name, properties.getProperty(name));
            }
        }
        return jo;
    }