JSONPath - filtered query returns array rather than string

I’ve noticed a limitation of jsonpath that seems to be biting me at the moment, and curious if anyone has run into this before and can share a solution.

I’m working on a custom Web Services connector, and noticed that all my attributes are coming back as single-item arrays rather than as strings (even though the schema attributes are not configured as multi-valued). While this displays fine in the UI (for the most part; the only place I can see that the values are arrays is the account name which is wrapped in square brackets [ ]), it’s very clear when you pull the list of accounts down via the ISC API.

My research has indicated that this is actually a long-known jsonpath limitation - once you apply a filter, you’re stuck with an array, and can’t even use [0] to address the first (and only) item in said array.

This can be reproduced with the default input in the SailPoint JSONPath Evaluator. A query that is analogous to what I’m trying to do is:
$.requestedItemsStatus[*].approvalInfo[?(@.approvalDecision=='APPROVED')].approverName

You can see that if you tack on a [0] to the end of that, you get an empty array.

The structure of the responses I’m getting from the Web Service is as follows:

{
    "parent": [
        {
            "attribute1": "12345",
            "attribute2": "ABC DEF",
            "attribute3": "1a2b3c4d5e6f",
            "fields": [
                {
                    "name": "ThisOne",
                    "value": "foo"
                },
                {
                    "name": "NotThisOne",
                    "value": "bar"
                }
            ]
        }
    ]
}

The expected result would be to have an attribute ThisOne with a value of foo, not a value of ["foo"]. Ideally, I’d like to solve this without needing to implement a rule…

Thanks!
-Mark

@sup3rmark - I was able to reproduce the issue you’re seeing: It unfortunately looks like there is no easy way to deal with it at the JSONPath level. JSONPath expressions always return an array, even if it is holding just the one element in it.

You might have to do it via a rule, as much as it pains for me to type this!

2 Likes

I have experienced this issue before and could not determine an easy fix, unfortunately.

Agreed with the gentleman above. JSONPath will always return an array in these cases, so you are stuck with implementing a rule to fix.

I’ve responded you on teams but, you can filter using it like that:

fields.[?(@.name =="Email")].value

No rule is necessary.

Cheers

Negative, this returns an array as explained above.

It looks like a rule is the only solution here.

Realistically, it seems like a bug on the SailPoint side, where a schema attribute that is configured as a string and not configured as a multi-valued attribute is still coming across as an array, rather than a string. IMO, this should be automatically converted to a string. Right?

It isn’t a SailPoint bug but the nature of JSONPath expressions. The results always end up being an array. It is surely inconvenient, and I wish there was an easier way to convert them to strings.

I’d argue that it could be considered a bug on the SailPoint side - I have a schema attribute configured as a string that is specifically not set as multi-valued, so it should only allow/store single-valued strings, rather than arrays. The graceful way would be for it to convert it to a string. The less-graceful way would be for it to throw an error.

1 Like