I am pretty new to java and rest. I was trying to count elements from the item object using rest. If you check below Json then you will find 6 elements associated with the item object.
{
"response": {
"status": "active",
"timestamp": "2019-01-02 20:07:42"
},
"group": [
{
"best_option": "Offer",
"item": {
"F": [
{
"code": "228"
}
],
"E": [
{
"code": "228"
}
]
},
"review": {
"F": [
{
"code": "110"
},
{
"code": "212"
}
],
"E": [
{
"code": "110"
},
{
"code": "212"
}
]
}
},
{
"best_option": "Offer",
"item": {
"D": [
{
"code": "228"
}
],
"C": [
{
"code": "228"
}
]
},
"review": {
"D": [
{
"code": "110"
},
{
"code": "212"
}
],
"C": [
{
"code": "110"
},
{
"code": "212"
},
{
"code": ""
}
]
}
},
{
"best_option": "Offer",
"item": {
"A": [
{
"code": "228"
}
]
},
"review": {
"A": [
{
"code": "110"
},
{
"code": "212"
}
]
}
},
{
"best_option": "Offer",
"item": {
"B": [
{
"code": "228"
},
{
"code": "662"
}
]
},
"review": {
"B": [
{
"code": "110"
},
{
"code": "662"
}
]
}
}
]
}
I have tried jsonResponse.getBody().jsonPath().get() to count element from item object. I want to count number of elements present in the item object for e.g: A, B, C,D,E F . Can someone please help me to sort out my issue?
item.*.codein aSetso that you can get the distinct value easily. This is quite simple to do but base on the JSON library you are using (if you are using one...) the solution may vary so I can't help you more