'JSONPath cannot query if condition is a child's property of array

I have a json as below. I want to select list reference of item which has method is "method A". But I cannot query with operator == (with Jayway JSONPath evaluation)

$.items[*].[?(@.methods[*].name == 'method A')].reference

But when I replace operator as contains, the jsonpath works.

$.items[*].[?(@.methods[*].name contains 'method A')].reference

I don't know why operator == does not work. Could anyone help me explain the reason? JSON:

{
    "name": "List codes",
    "items": [
        {            
            "name": "Cash",
            "reference": "CA",
            "methods": [
                {                    
                    "name": "method A",
                    "id": "3543"
                },
                {
                    "name": "method B",
                    "id": "3544"
                }
            ]
        },
        {            
            "name": "Debt",
            "reference": "DE",
            "methods": [
                {                    
                    "name": "method C",
                    "id": "3545"
                },
                {
                    "name": "method B",
                    "id": "3544"
                }
            ]
        },
        {            
            "name": "Property",
            "reference": "PR",
            "methods": [
                {                    
                    "name": "method C",
                    "id": "3545"
                },
                {
                    "name": "method A",
                    "id": "3543"
                }
            ]
        }
    ]
}


Solution 1:[1]

@.methods[*].name will yield multiple results resulting into an array. You cannot use == to compare list of values with a string.

if you need to use == operator then you have to use the index along with ||

$.items[?(@.methods[0].name == 'method A' || @.methods[1].name == 'method A')].reference

Solution 2:[2]

There are some factors you need to consider to debug the issue:

  1. Make sure that location access enables. await Location.hasServicesEnabledAsync()

  2. There's a probability that, recently, you deny location permission definitively. requestForeground.status will always resolve as denied

Detect if requestForeground.canAskAgain set to true otherwise user has already denied this permission and you can open device setting and user grant that permission manually.

Here permission response type definition

export interface PermissionResponse {
  status: PermissionStatus;
  expires: PermissionExpiration;
  granted: boolean;
  canAskAgain: boolean;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akshay G
Solution 2 Shy Penguin