Converts this instance to its JSON representation.

@return the JSON representation of these settings
@throws IOException   if an I/O error occurs
@throws JSONException if an error occurs while encoding these settings as JSON
970803
public JSONObject toJson() throws IOException, JSONException {
    JSONObject json = new JSONObject();

    for (CapabilityInstance option : options.values()) {
      Object value = option.getValue();

      if (value == null) {
        continue;
      }

      if (value instanceof OperaProfile) {
        value = ((OperaProfile) value).toJson();
      } else if (value instanceof OperaArguments && ((OperaArguments) value).size() > 0) {
        value = ((OperaArguments) value).toJson();
      } else if (value instanceof Boolean) {
        value = (Boolean) value ? 1 : 0;
      } else {
        value = String.valueOf(value);
      }

      json.put(option.getIdentifier(), value);
    }

    return json;
  }
979035
public String toJsonString() throws Exception {
		List<?> rootContainerJsonList = (List<?>) Json.runtimeObjectToJToken(mainContentContainer);

		HashMap<String, Object> rootObject = new HashMap<String, Object>();
		rootObject.put("inkVersion", inkVersionCurrent);
		rootObject.put("root", rootContainerJsonList);

		return SimpleJson.HashMapToText(rootObject);
	}
58411
JSONObject toJson() {
        JSONObject ret = new JSONObject();
        ret.put("type",type.name());
        if (targetConfig != null) {
            ret.put("target",targetConfig.toJson());
        }
        return ret;
    }
594914
private byte[] toStorageJson() {
    final ByteArrayOutputStream output = new ByteArrayOutputStream(
        display_name.length() + tsuid.length() + 30);
    try {
      final JsonGenerator json = JSON.getFactory().createGenerator(output);
      
      json.writeStartObject();
      
      // we only need to write a small amount of information
      json.writeObjectField("displayName", display_name);
      json.writeObjectField("tsuid", tsuid);
      
      json.writeEndObject();
      json.close();
      
      // TODO zero copy?
      return output.toByteArray();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
551676
public JSONObject getRawDataAsJson() throws IOException
    {
        String input = getRawDataAsString();
        if ( input == null ) {
            return null;
        }
        
        return new JSONObject(input);
    }
769946
public static JsonValue serializeAsJson(Object o) throws IOException {
        try {
            return findFieldsToSerialize(o).mainObject;
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
1117300
public String toJson() {
        logger.entering();

        parseResults();

        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String json = gson.toJson(this);
        logger.exiting(json);
        return json;
    }
488476
public String encode() {
    // System.out.println(toJson());
    if (base64 == null)
      base64 = new String(
        Base64.getUrlEncoder().encode(toJson().toString().getBytes(StandardCharsets.UTF_8)),
        StandardCharsets.UTF_8
      );
    return base64;
  }
914392
@SuppressWarnings("all")
    public JSONObject toJSONObject() {
        try {
            return Reflection.toType(this, JSONObject.class);
        } catch (Throwable e) {
            throw new RuntimeException("The output cannot be converted to jsonObject!", e);
        }
    }
102019
protected byte[] jsonSerialize(Object o) {
        byte[] res = null;
        try {
            res = JsonUtils.toJson(o).getBytes("utf-8");
        } catch (UnsupportedEncodingException e) {
            logger.error("JsonSerialize object fail ", e);
        }
        return res;
    }
688535
public byte[] toCompressedJSON() throws IOException {
        // Wrap a GZIPOuputStream around a ByteArrayOuputStream.
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        GZIPOutputStream gzipOut = new GZIPOutputStream(bytesOut);
        
        // Wrap the GZIPOutputStream with an OutputStreamWriter that convers JSON Unicode
        // text to bytes using UTF-8.
        OutputStreamWriter writer = new OutputStreamWriter(gzipOut, Utils.UTF8_CHARSET);
        
        // Create a JSONEmitter that will write its output to the writer above and generate
        // the JSON output.
        JSONEmitter json = new JSONEmitter(writer);
        json.startDocument();
        toJSON(json);
        json.endDocument();
        
        // Ensure the output stream is flushed and the GZIP is finished, then the output
        // buffer is complete.
        writer.flush();
        gzipOut.finish();
        return bytesOut.toByteArray();
    }
102039
@NonNull
  public String toJson() {
    Gson gson = new GsonBuilder()
      .registerTypeAdapterFactory(GeometryAdapterFactory.create())
      .registerTypeAdapter(BoundingBox.class, new BoundingBoxTypeAdapter())
      .registerTypeAdapterFactory(GeocodingAdapterFactory.create())
      .create();
    return gson.toJson(this, GeocodingResponse.class);
  }
109755
public static String toJson(Object obj) {
        StringWriter sw = new StringWriter();
        ObjectMapper mapper = getDefaultObjectMapper();
        try {
            JsonGenerator jg = mapper.getFactory().createGenerator(sw);
            mapper.writeValue(jg, obj);
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (JsonGenerationException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sw.toString();
    }
267340
protected JsonObject argumentsToJson() {
    JsonObject result = new JsonObject();
    for (Argument a : _arguments) {
      if (a.specified())
        result.addProperty(a._name,a.originalValue());
    }
    return result;
  }
327186
public final PJsonObject toJSON() {
        try {
            JSONObject json = new JSONObject();
            for (String key: this.obj.keySet()) {
                Object opt = opt(key);
                if (opt instanceof PYamlObject) {
                    opt = ((PYamlObject) opt).toJSON().getInternalObj();
                } else if (opt instanceof PYamlArray) {
                    opt = ((PYamlArray) opt).toJSON().getInternalArray();
                }
                json.put(key, opt);
            }
            return new PJsonObject(json, this.getContextName());
        } catch (Throwable e) {
            throw ExceptionUtils.getRuntimeException(e);
        }
    }
289187
public String toJSON() {
		StringBuilder json = new StringBuilder();
		json.append("[");
		for (int t = 0; t < components.size(); t++) {
			if (t > 0)
				json.append(",");
			T component = components.get(t);
			json
				.append("{")
				.append("\"label\":\"").append(component.getDisplayName()).append("\"")
				.append(",\"id\":\"").append(component.getId()).append("\"")
				.append("}")
			;
		}
		json.append("]");
		return json.toString();
	}
1071924
public JSONObject toJson() throws JSONException {
    JSONObject json = new JSONObject();

    for (OperaArgument argument : this) {
      json.put(argument.getArgument(), argument.getValue());
    }

    return json;
  }