Java Utililty Methods Json Get

List of utility methods to do Json Get

Description

The list of methods to do Json Get are organized into topic(s).

Method

JsonObjectgetJsonObject(JsonObject object, String name)
get Json Object
if (hasKey(object, name)) {
    return object.getJsonObject(name);
return null;
JsonValuegetJsonValue(String json_path, JsonObject response)
get Json Value
StringTokenizer tk = new StringTokenizer(json_path, "/");
JsonValue rValue = response;
JsonObject value = response;
while (tk.hasMoreTokens()) {
    String key = tk.nextToken();
    rValue = value.get(key);
    if (rValue == null || (rValue.getValueType() != ValueType.OBJECT)) {
        break;
...
StringgetKeyAsString(JsonObject obj, String key, String defaultValue)
get Key As String
String value = defaultValue;
if (obj.containsKey(key)) {
    value = obj.get(key).toString();
return value;
longgetLongProperty(JsonObject object, String property)
get Long Property
return object.getJsonNumber(property).longValue();
JsonWriterFactorygetPrettyJsonWriterFactory()
get Pretty Json Writer Factory
if (null == FACTORY_INSTANCE) {
    final Map<String, Object> properties = new HashMap<>(1);
    properties.put(JsonGenerator.PRETTY_PRINTING, true);
    FACTORY_INSTANCE = Json.createWriterFactory(properties);
return FACTORY_INSTANCE;
JsonArraygetSitesFromDb(String replicationSitesInDB)
The reason this in JSON is that it probably makes sense to someday query RSAL or some other "big data" component live for a list of remotes sites to which a particular dataset is replicated to.
JsonArrayBuilder arraybuilder = Json.createArrayBuilder();
if (replicationSitesInDB == null || replicationSitesInDB.isEmpty()) {
    return arraybuilder.build();
String[] sites = replicationSitesInDB.split(",");
for (String site : sites) {
    String[] parts = site.split(":");
    arraybuilder.add(Json.createObjectBuilder().add("fqdn", parts[0]).add("name", parts[1]).add("country",
...
StringgetString(JsonObject jso, String name)
Gets a string value.
if (jso != null && jso.containsKey(name) && !jso.isNull(name)) {
    JsonValue v = jso.get(name);
    if (v.getValueType().equals(ValueType.STRING)) {
        return jso.getString(name);
    } else if (v.getValueType().equals(ValueType.NUMBER)) {
return null;
...
StringgetValueFromJson(JsonObject currentJsonObject, String key)
get Value From Json
String result = "";
if (currentJsonObject.containsKey(key)) {
    switch (currentJsonObject.get(key).getValueType()) {
    case STRING:
        result = currentJsonObject.getString(key);
        break;
    case NUMBER:
        result = String.valueOf(currentJsonObject.getInt(key));
...