I have a JSON that has a similar structure to the one below (end of post). I'm trying to read it from a file and then extract some information. I'd like to get the "times" child and do something with it. I've tried using json.simple and some of the jackson stuff but I keep getting casting/type errors. I'm pretty stuck :/
First I read in the file and it seems to be correctly captured:
JSONParser parser = new JSONParser();
JSONObject data = (JSONObject) parser.parse(new FileReader("test.json"));
I then tried following this: Java JSONObject get children
but get errors org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject
What I want (think is what I want?) to do is something along the lines create a JSON of the times, and then from there I can make a list of the times/do various operations with them. Or maybe the best approach is to use an ObjectMapper and map it to a matching object?
{
"id": "ca1b57be-6c38-4976-9050-f9a95a05a38d",
"name": "some name",
"results": [
{
"name": "https://st-dev.aexp.com/smart-test/v1/test/test",
"tests": {
"name": "Body matches string",
"status": "pass",
"Response time is less than 200ms": true
},
"testPassFailCounts": {
"Body matches string": {
"pass": 100,
"fail": 0
},
"Response time is less than 200ms": {
"pass": 100,
"fail": 0
}
},
"times": [
"48",
"25",
"25",
"28",
"24",
"24",
"35",
"29",
"41",
"28",
"28",
"24",
"31",
"28",
"25",
"27",
"23",
"28",
"44",
"29",
"25",
"23",
"44",
"28",
"22"
]
}
]
}
Thanks much for any help!