Example usage for org.json.simple JSONObject put

List of usage examples for org.json.simple JSONObject put

Introduction

In this page you can find the example usage for org.json.simple JSONObject put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:fr.zcraft.zlib.components.rawtext.RawTextPart.java

static private JSONObject actionToJSON(Enum action, Object value) {
    JSONObject obj = new JSONObject();
    obj.put("action", action.name().toLowerCase());
    obj.put("value", value);
    return obj;/*w ww.j a va2s  .  com*/
}

From source file:com.opensoc.json.serialization.JSONEncoderHelper.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static JSONObject getJSON(Configuration config) {

    JSONObject output = new JSONObject();

    if (!config.isEmpty()) {
        Iterator it = config.getKeys();
        while (it.hasNext()) {
            String k = (String) it.next();
            // noinspection unchecked
            String v = (String) config.getProperty(k);
            output.put(k, v);
        }/*from  w w  w.  java2 s.  c o m*/
    }
    return output;
}

From source file:com.tom.deleteme.PrintAnnotations.java

public static void appendOtherNamedTags(JSONObject json, String coveredText) {
    String otherNamedTags = (String) json.get(OtherNamedTagsKey);
    StringJoiner joiner = new StringJoiner(",");
    joiner.add(otherNamedTags).add(coveredText);
    String joinedString = joiner.toString();
    json.put(OtherNamedTagsKey, joinedString);
}

From source file:cat.tv3.eng.rec.recomana.lupa.visualization.ClustersToJson.java

public static JSONArray fullestoArray(String[] instance_group_keys, Jedis jedis) {
    JSONArray result = new JSONArray();
    JSONObject info = new JSONObject();
    for (int i = 0; i < instance_group_keys.length; ++i) {
        String[] instancesOfGroup = jedis.smembers(instance_group_keys[i]).toArray(new String[0]);
        for (int j = 0; j < instancesOfGroup.length; ++j) {
            info = new JSONObject();
            info.put("name", instancesOfGroup[j]);
            result.add(info);//from  w w w. ja  va 2  s. c  o m
        }
    }
    return result;
}

From source file:component.Configuration.java

public static void createConfigFile() throws IOException {
    JSONObject config = new JSONObject();
    List<String> queryList = new ArrayList<>();
    Map<String, List<String>> queries = new HashMap<>();
    try (Writer writer = new FileWriter("config.json", false)) {
        queryList.add("full_message:(Exception)");
        queryList.add("full_message:(Error)");
        config.put("queries", queryList);
        config.put("range", 3600);

        config.writeJSONString(writer);//w ww.  j a v a 2  s.c  o  m
        writer.flush();
    }
}

From source file:io.personium.test.jersey.box.odatacol.schema.property.PropertyUtils.java

/**
 * Property?./*from  ww w.j a  va 2s. c o  m*/
 * @param token 
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param srcPropertyName ?Property??
 * @param srcEntityTypeName ?EntityType??
 * @param propertyName ??Property??
 * @param entityTypeName ??EntityType??
 * @param type Property?Type
 * @param nullable Property?Nullable
 * @param defaultValue Property?DefaultValue
 * @param collectionKind Property?collectionKind
 * @param isKey Property?isKey
 * @param uniqueKey Property?UniqueKey
 * @return ?
 */
@SuppressWarnings("unchecked")
public static PersoniumResponse update(String token, String cell, String box, String collection,
        String srcPropertyName, String srcEntityTypeName, String propertyName, String entityTypeName,
        String type, Boolean nullable, Object defaultValue, String collectionKind, Boolean isKey,
        String uniqueKey) {

    // ???
    JSONObject body = new JSONObject();
    body.put("Name", propertyName);
    body.put("_EntityType.Name", entityTypeName);
    body.put("Type", type);
    body.put("Nullable", nullable);
    body.put("DefaultValue", defaultValue);
    body.put("CollectionKind", collectionKind);
    body.put("IsKey", isKey);
    body.put("UniqueKey", uniqueKey);

    return update(token, cell, box, collection, srcPropertyName, srcEntityTypeName, body);

}

From source file:io.personium.test.jersey.box.odatacol.schema.property.PropertyUtils.java

/**
 * PropertyEntityType??NP??.//from  ww w  .  j a  v  a2s. c o m
 * @param token 
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param entityTypeName EntityType??
 * @param propertyName Property??
 * @param type Property?Type
 * @param nullable Property?Nullable
 * @param defaultValue Property?DefaultValue
 * @param collectionKind Property?collectionKind
 * @param isKey Property?isKey
 * @param uniqueKey Property?UniqueKey
 * @param code ??
 * @return ?
 */
@SuppressWarnings("unchecked")
public static TResponse createViaPropertyNP(String token, String cell, String box, String collection,
        String entityTypeName, String propertyName, String type, Boolean nullable, String defaultValue,
        String collectionKind, Boolean isKey, String uniqueKey, int code) {

    // ???
    JSONObject body = new JSONObject();
    body.put("Name", propertyName);
    body.put("_EntityType.Name", entityTypeName);
    body.put("Type", type);
    body.put("Nullable", nullable);
    body.put("DefaultValue", defaultValue);
    body.put("CollectionKind", collectionKind);
    body.put("IsKey", isKey);
    body.put("UniqueKey", uniqueKey);

    TResponse res = Http.request("box/odatacol/schema/createViaNP.txt").with("cell", cell).with("box", box)
            .with("collection", collection).with("accept", MediaType.APPLICATION_JSON)
            .with("contentType", MediaType.APPLICATION_JSON).with("token", PersoniumUnitConfig.getMasterToken())
            .with("entityType", "EntityType").with("id", entityTypeName).with("navPropName", "_Property")
            .with("body", body.toJSONString()).returns().statusCode(code).debug();
    return res;
}

From source file:net.duckling.ddl.web.controller.pan.PanFileMoveController.java

private static void writeResponse(HttpServletResponse response, int state, String message) {
    JSONObject msg = new JSONObject();
    msg.put("state", state);
    msg.put("msg", message);
    JsonUtil.writeJSONObject(response, msg);
}

From source file:co.alligo.toasted.routes.Announce.java

public static String announce(Request req, Response res, Servers servers) {
    JSONObject json = new JSONObject();
    JSONObject result = new JSONObject();
    String ip = req.ip();/*from w w  w.j  av a2s  .c  om*/
    String port;

    res.header("Content-Type", "application/json");

    if (!(req.headers("x-forwarded-for") == null)) {
        ip = req.headers("x-forwarded-for");
    }

    if (req.attribute("port") == null) {
        result.put("code", 1);
        result.put("msg", "Invalid parameters, valid parameters are 'port' (int) and 'shutdown' (bool)");
        json.put("result", result);
        return json.toJSONString();
    } else {
        port = req.attribute("port").toString();
    }

    if ("true".equals(req.attribute("shutdown").toString())) {
        servers.delServer(ip, port);
    } else {
        if (checkGameServer(ip, port)) {
            servers.addServer(ip, port);
            result.put("code", 0);
            result.put("msg", "Added server to list.");
            System.out.println("Added server to list" + ip + ":" + port);
            json.put("result", result);
            return json.toJSONString();

        } else {
            result.put("code", 0);
            result.put("msg", "Failed to contact game server, are the ports open and forwarded correctly?");
            json.put("result", result);
            return json.toJSONString();
        }
    }

    return "500 Internal Server Error";
}

From source file:com.fujitsu.dc.test.utils.RoleUtils.java

/**
 * Role??./*w  w  w.  jav  a 2 s . c  om*/
 * @param cellName ??
 * @param token 
 * @param boxName ??
 * @param roleName ??
 * @param code ?
 * @return ?
 */
@SuppressWarnings("unchecked")
public static TResponse create(final String cellName, final String token, final String boxName,
        final String roleName, final int code) {
    JSONObject body = new JSONObject();
    body.put("Name", roleName);
    if (boxName != null) {
        body.put("_Box.Name", boxName);
    }

    return Http.request("role-create.txt").with("token", token).with("cellPath", cellName)
            .with("body", body.toString()).returns().statusCode(code);
}