String loudScreaming = json.getJSONObject("LabelData").getString("slogan");
Answer from phihag on Stack OverflowOracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonObject.html
JsonObject (Java(TM) EE 7 Specification APIs)
... the array value to which the specified name is mapped, or null if this object contains no mapping for the name ... ClassCastException - if the value to which the specified name is mapped is not assignable to JsonArray type ... Returns the object value to which the specified name is mapped. This ...
Top answer 1 of 4
159
String loudScreaming = json.getJSONObject("LabelData").getString("slogan");
2 of 4
10
If it's a deeper key/value you're after and you're not dealing with arrays of keys/values at each level, you could recursively search the tree:
public static String recurseKeys(JSONObject jObj, String findKey) throws JSONException {
String finalValue = "";
if (jObj == null) {
return "";
}
Iterator<String> keyItr = jObj.keys();
Map<String, String> map = new HashMap<>();
while(keyItr.hasNext()) {
String key = keyItr.next();
map.put(key, jObj.getString(key));
}
for (Map.Entry<String, String> e : (map).entrySet()) {
String key = e.getKey();
if (key.equalsIgnoreCase(findKey)) {
return jObj.getString(key);
}
// read value
Object value = jObj.get(key);
if (value instanceof JSONObject) {
finalValue = recurseKeys((JSONObject)value, findKey);
}
}
// key is not found
return finalValue;
}
Usage:
JSONObject jObj = new JSONObject(jsonString);
String extract = recurseKeys(jObj, "extract");
Using Map code from https://stackoverflow.com/a/4149555/2301224
Videos
Baeldung
baeldung.com › home › json › getting a value in jsonobject
Getting a Value in JSONObject | Baeldung
May 5, 2025 - The generic method returns an Object instance, while the specific methods return an already casted instance. Let’s get the “family” field of the JSON data using the generic get() method. We assume that the JSON data has been preliminarily loaded into the jsonObject variable, which is of JSONObject type:
Stleary
stleary.github.io › JSON-java › org › json › JSONObject.html
JSONObject
Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names. The internal form is an object having get and opt methods for accessing the values by name, and put methods for adding or replacing values by name.
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › org.json.jsonobject.get
JSONObject.Get(String) Method (Org.Json) | Microsoft Learn
November 18, 2022 - [<Android.Runtime.Register("get", "(Ljava/lang/String;)Ljava/lang/Object;", "GetGet_Ljava_lang_String_Handler")>] abstract member Get : string -> Java.Lang.Object override this.Get : string -> Java.Lang.Object ... Returns the value mapped by name, or throws if no such mapping exists. Java documentation for org.json.JSONObject.get(java.lang.String).
Android Developers
developer.android.com › api reference › jsonobject
JSONObject | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
Microsoft Learn
learn.microsoft.com › en-us › dynamics365 › business-central › dev-itpro › developer › methods-auto › jsonobject › jsonobject-get-method
JsonObject.Get(Text, var JsonToken) Method - Business Central | Microsoft Learn
[Ok := ] JsonObject.Get(Key: Text, var Result: JsonToken)
Oracle
docs.oracle.com › cd › F10042_01 › reference-java-api › oracle › adfmf › json › JSONObject.html
JSONObject (Oracle Fusion Middleware Java API Reference for Oracle Mobile Application Framework)
Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names. The internal form is an object having get and opt methods for accessing the values by name, and put methods for adding or replacing values by name.
TutorialsPoint
tutorialspoint.com › how-to-get-the-values-of-the-different-types-from-a-json-object-in-java
How to get the values of the different types from a JSON object in Java?
Create a JSONObject object and pass the JSON string to it. Use the getString(), getInt(), getDouble(), and getBoolean() methods to extract the values of different types from the JSON object.
Spring
docs.spring.io › spring-boot › docs › 2.3.0.M2 › api › org › springframework › boot › configurationprocessor › json › JSONObject.html
JSONObject (Spring Boot 2.3.0.M2 API)
public JSONObject getJSONObject(String name) throws JSONException · Returns the value mapped by name if it exists and is a JSONObject. Parameters: name - the name of the property · Returns: the value · Throws: JSONException - if the mapping doesn't exist or is not a JSONObject.
Apache
sling.apache.org › apidocs › sling8 › org › apache › sling › commons › json › JSONObject.html
JSONObject (Apache Sling 8 API)
Get the JSONArray value associated with a key. ... A JSONArray which is the value. ... JSONException - if the key is not found or if the value is not a JSONArray. public JSONObject getJSONObject(String key) throws JSONException
Couchbase
docs.couchbase.com › sdk-api › couchbase-java-client › com › couchbase › client › java › json › JsonObject.html
JsonObject (Couchbase Java SDK 3.11.1 API)
Static method to create a JsonObject from a JSON String. Object · get · (String name) Retrieves the (potential null) content and not casting its type. JsonArray · getArray · (String name) Retrieves the value from the field name and casts it to JsonArray. BigDecimal ·
SourceForge
json-lib.sourceforge.net › apidocs › jdk15 › net › sf › json › JSONObject.html
JSONObject (Overview (json-lib jdk 5 API))
Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names. The internal form is an object having get and opt methods for accessing the values by name, and put methods for adding or replacing values by name.
Google Groups
groups.google.com › g › vertx › c › mhJEi0viEsw
Generically get the value from a JSON object using JsonObject
public Object getValue(String key) { Objects.requireNonNull(key); Object val = map.get(key); if (val instanceof Map) { val = new JsonObject((Map)val); } else if (val instanceof List) { val = new JsonArray((List)val); } return val; } So JsonObject provides a generic getter already.
Javadoc.io
javadoc.io › doc › com.google.code.gson › gson › 2.6.2 › com › google › gson › JsonObject.html
JsonObject - gson 2.6.2 javadoc
Bookmarks · Latest version of com.google.code.gson:gson · https://javadoc.io/doc/com.google.code.gson/gson · Current version 2.6.2 · https://javadoc.io/doc/com.google.code.gson/gson/2.6.2 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/com.goog...
GitHub
github.com › stleary › JSON-java › blob › master › src › main › java › org › json › JSONObject.java
JSON-java/src/main/java/org/json/JSONObject.java at master · stleary/JSON-java
* A JSONObject is an unordered collection of name/value pairs. Its external · * form is a string wrapped in curly braces with colons between the names and · * values, and commas between the values and names.
Author stleary
Jakarta EE
jakarta.ee › specifications › platform › 8 › apidocs › javax › json › jsonobject
JsonObject (Jakarta EE 8 Specification APIs)
... the array value to which the specified name is mapped, or null if this object contains no mapping for the name ... ClassCastException - if the value to which the specified name is mapped is not assignable to JsonArray type ... Returns the object value to which the specified name is mapped. This ...