-1

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?

User1974
  • 276
  • 1
  • 17
  • 63

1 Answers1

1

Start here, by passing the JSON string into the parse function.

parse documentation

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.

PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56