I have a JSON as follows
[
{
"a": "John",
"id": "6",
"c": "val1"
},
{
"a": "Jack",
"id": "6",
"c": "val2"
},
{
"a": "Joe",
"id": "6",
"c": "val3"
}
]
I need to convert it into a Map<String, String> such that the values of the fields 'a' become the key and the values of the fields 'c' become the value in the Map.
In other words, my Map should look like the below:
John:val1
Jack:val2
Joe:val3
What is the shortest way to do this?
Also, I was wondering if in any way RestAssured GPath can be leveraged here
Something like this -
new JsonPath(jsonPayload).getString("findAll { json -> json.id == '6' }.a");
You can use
jackson
for example:I would create a wrapper for the resulting
Map
and a custom deserializer.The deserializer:
A simple test: