Refine search
public static void main(String[] args) throws IOException { // convert Java to writer JsonObject root = Json.object().add("message", "Hi").add( "place", Json.object().add("name", "World!") ); StringWriter writer = new StringWriter(); root.writeTo(writer); String json = writer.toString(); System.out.println(json); System.out.println(); // convert writer to Java JsonObject obj = Json.parse(json).asObject(); String message = obj.get("message").asString(); String name = obj.get("place").asObject().get("name").asString(); System.out.println(message + " " + name); } }
private static JsonObject extractMeasurement(JsonObject measurement) { JsonObject times = measurement.get("v").asObject() .get("measurementSetMap").asObject() .get("TIME").asObject(); return new JsonObject().add("variables", measurement.get("k").asObject().get("variables")) .add("units", times.get("unitNames")) .add("values", extractTimes(times.get("measurements").asArray())); }
/** * Sets the value of the member with the specified name to the JSON representation of the * specified <code>long</code> value. If this object does not contain a member with this name, a * new member is added at the end of the object. If this object contains multiple members with * this name, only the last one is changed. * <p> * This method should <strong>only be used to modify existing objects</strong>. To fill a new * object with members, the method <code>add(name, value)</code> should be preferred which is much * faster (as it does not need to search for existing members). * </p> * * @param name * the name of the member to replace * @param value * the value to set to the member * @return the object itself, to enable method chaining */ public JsonObject set(String name, long value) { set(name, Json.value(value)); return this; }
JsonObject json = JsonObject.readFrom(FileUtils.readFileToString(configJson)); if (json.get("platform") != null) { platform = Platform.byDesc(json.get("platform").asString()); if (json.get("jdk") != null) { jdk = json.get("jdk").asString(); if (json.get("executable") != null) { executable = json.get("executable").asString(); if (json.get("classpath") != null) { classpath = toStringArray(json.get("classpath").asArray()); if (json.get("removelibs") != null) { removePlatformLibs = toStringArray(json.get("removelibs").asArray()); if (json.get("mainclass") != null) { mainClass = json.get("mainclass").asString(); if (json.get("vmargs") != null) { List<String> vmArgs = toStringArray(json.get("vmargs").asArray()); this.vmArgs = new ArrayList<>(); for (String vmArg : vmArgs) { if (json.get("minimizejre") != null) { minimizeJre = json.get("minimizejre").asString(); if (json.get("cachejre") != null) {
@Override protected void setUp() throws IOException { jsonObject = new JsonObject(); for (int index = 0; index < size; index++) { String name = Integer.toHexString(index); jsonObject.add(name, index); } }
private void decomposeJSONValue(String name, JsonValue val, Map<String, String> map) { if (val.isObject()) { JsonObject obj = val.asObject(); for (String memberName : obj.names()) { this.decomposeJSONValue(name + "." + memberName, obj.get(memberName), map); } } else if (val.isArray()) { JsonArray arr = val.asArray(); for (int i = 0; i < arr.size(); i++) { this.decomposeJSONValue(name + "[" + i + "]", arr.get(i), map); } } else { map.put(name, val.toString()); } }
/** * {@inheritDoc} */ @Override void parseJSONMember(JsonObject.Member member) { super.parseJSONMember(member); String memberName = member.getName(); JsonValue value = member.getValue(); try { if (memberName.equals("assigned_to")) { JsonObject assignmentJSON = value.asObject(); this.assignedToType = assignmentJSON.get("type").asString(); this.assignedToID = assignmentJSON.get("id").asString(); } else if (memberName.equals("storage_policy")) { JsonObject storagePolicyJSON = value.asObject(); this.storagePolicyID = storagePolicyJSON.get("id").asString(); this.storagePolicyType = storagePolicyJSON.get("type").asString(); } } catch (ParseException e) { assert false : "A ParseException indicates a bug in the SDK."; } } }
public static Observation deserialize(byte[] data) { JsonObject v = (JsonObject) Json.parse(new String(data)); EndpointContext endpointContext = EndpointContextSerDes.deserialize(v.get("peer").asObject()); byte[] req = Hex.decodeHex(v.getString("request", null).toCharArray()); RawData rawData = RawData.outbound(req, endpointContext, null, false); Request request = (Request) parser.parseMessage(rawData); request.setDestinationContext(endpointContext); JsonValue ctxValue = v.get("context"); if (ctxValue != null) { Map<String, String> context = new HashMap<>(); JsonObject ctxObject = (JsonObject) ctxValue; for (String name : ctxObject.names()) { context.put(name, ctxObject.getString(name, null)); } request.setUserContext(context); } return new Observation(request, endpointContext); }
private void addDependencies(JsonObject fraction, FractionDescriptor parent) { fraction.get("fractionDependencies").asArray().forEach(entry -> { JsonObject dependency = entry.asObject(); FractionDescriptor descriptor = getFractionDescriptor(dependency); if (parent != null) { parent.addDependency(descriptor); } addDependencies(dependency, descriptor); }); }
public static String upload(byte[] data, ImageType type, JsonObject extra, ChatImpl chat) throws ConnectionException { JsonObject obj = new JsonObject(); obj.add("type", type.mime); obj.add("permissions", new JsonObject().add(chat.getIdentity(), new JsonArray().add("read"))); if (extra != null) extra.forEach(m -> obj.add(m.getName(), m.getValue())); JsonObject response = Endpoints.OBJECTS .open(chat.getClient()) .as(JsonObject.class) .expect(201, "While uploading data") .post(obj); String id = response.get("id").asString(); Endpoints.UPLOAD_IMAGE .open(chat.getClient(), id, type.endpoint) .header("Content-Type", "multipart/form-data") .expect(201, "While uploading data") .connect("PUT", data); Endpoints.EndpointConnection<JsonObject> econn = Endpoints.IMG_STATUS .open(chat.getClient(), id, type.id) .as(JsonObject.class) .expect(200, "While getting upload status"); while (true) { JsonObject status = econn.get(); if (status.get("view_state").asString().equals("ready")) { break; } } return id; }
JsonArray reduceArray = minimizeJson.get("reduce").asArray(); for (JsonValue reduce : reduceArray) { String path = reduce.asObject().get("archive").asString(); File file = new File(output, path); JsonArray removeArray = reduce.asObject().get("paths").asArray(); for (JsonValue remove : removeArray) { File removeFile = new File(fileNoExt, remove.asString()); JsonArray removeArray = minimizeJson.get("remove").asArray(); for (JsonValue remove : removeArray) { String platform = remove.asObject().get("platform").asString(); JsonArray removeFilesArray = remove.asObject().get("paths").asArray(); for (JsonValue removeFile : removeFilesArray) { removeFileWildcard(output, removeFile.asString(), config);
public synchronized String[] getWalletPublicAddressesWithUnspentOutputs() throws WalletCallException, IOException, InterruptedException { JsonArray jsonUnspentOutputs = executeCommandAndGetJsonArray("listunspent", "0"); Set<String> addresses = new HashSet<>(); for (int i = 0; i < jsonUnspentOutputs.size(); i++) { JsonObject outp = jsonUnspentOutputs.get(i).asObject(); addresses.add(outp.getString("address", "ERROR!")); } return addresses.toArray(new String[0]); }
private BoxFileUploadSession.Info createUploadSession(BoxAPIConnection boxApi, URL url, long fileSize) { BoxJSONRequest request = new BoxJSONRequest(boxApi, url, HttpMethod.POST); //Creates the body of the request JsonObject body = new JsonObject(); body.add("file_size", fileSize); request.setBody(body.toString()); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject jsonObject = JsonObject.readFrom(response.getJSON()); String sessionId = jsonObject.get("id").asString(); BoxFileUploadSession session = new BoxFileUploadSession(boxApi, sessionId); return session.new Info(jsonObject); }
@Override public void updated(RegistrationUpdate update, Registration updatedRegistration, Registration previousRegistration) { JsonObject value = new JsonObject(); value.add("regUpdate", RegistrationUpdateSerDes.jSerialize(update)); value.add("regUpdated", RegistrationSerDes.jSerialize(updatedRegistration)); try (Jedis j = pool.getResource()) { j.publish(UPDATE_EVENT, value.toString()); } }
private static JsonObject getObject(SkypeImpl skype, String username) throws ConnectionException { JsonArray array = Endpoints.PROFILE_INFO .open(skype) .expect(200, "While getting contact info") .as(JsonArray.class) .post(new JsonObject() .add("usernames", new JsonArray() .add(username) ) ); return array.get(0).asObject(); }
private KeyValuePair lookForJwtInJsonObject(JsonObject object) { KeyValuePair rec; for (String name : object.names()) { if (object.get(name).isString()) { if (TokenCheck.isValidJWT(object.get(name).asString())) { return new KeyValuePair(name, object.get(name).asString().trim()); } } else if (object.get(name).isObject()) { if ((rec = lookForJwtInJsonObject(object.get(name).asObject())) != null) { return rec; } } } return null; }
public synchronized String getOperationFinalErrorMessage(String opID) throws WalletCallException, IOException, InterruptedException { JsonArray response = this.executeCommandAndGetJsonArray( "z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]")); JsonObject jsonStatus = response.get(0).asObject(); JsonObject jsonError = jsonStatus.get("error").asObject(); return jsonError.getString("message", "ERROR!"); }