I have a Stack Overflow question where I'm attempting to use Jython to extract a field value from JSON text:
Jython: Parse JSON object to get value (using Java functions)
A Stack Overflow community member has been kind enough to point me towards some Java documentation:
IBM >> Maximo >> Class JSONObject (Java)
Unfortunately, I've been staring at the Java documentation page for hours now, and to be honest, I have absolutely no idea what I'm looking at.
Where does this documentation show me how to extract a value from JSON text?
In other words, how do interpret this cryptic Java class documentation?
Start here, by passing the JSON string into the parse function.
Then, once you have your JSONObject
, you can traverse the tree treating the object as a HashMap.
String jsonInput = "{ 'foo':'bar' }";
JSONObject jsonObject = JSONObject.parse(jsonInput);
String fooValue = jsonObject.get('foo');
Of course, this is the hard way. You might consider a more fluid library like JsonPath, which also has documentation that's more fluid.