cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Check array is empty or not

Gayathry
New Contributor II

Hi Experts,

I have a requirement where I need to check โ€˜groupโ€™ array is empty or not. Could someone help with the JSON path expression.

Empty group array JSON looks like:
[
{
โ€œgroupโ€: [
{}
]
}
]
Non empty group array json loiks like:

[
{
โ€œgroupโ€: [
{
โ€œIDโ€: โ€œ002โ€
}
{
โ€œIDโ€: โ€œ003โ€
}
]
}
]

Thanks in Advance.

7 REPLIES 7

Gayathry
New Contributor II

Thanks a lot Bojan. instead if using โ€˜IDโ€™ in json path expression is there any other way to check list is empty as the object โ€˜IDโ€™ name is a dynamic one.

Yes @Gayathry , try this:

$group.filter(x=>x.keys().length != 0).length > 0

Gayathry
New Contributor II

Thank you so much. It worked.