Can JMESPath parse string as JSON object? Is this feature supported? If not what is the best way to handle strings?

Grafana uses JMESPath for role_attribute_path. I am using okta custom scope where I get JSON with string values.

JMESPath is unable to evaluate the strings and expect JSON object. What is the best way to handle this?

I have a sample okta response which shows →

{"Options": "{\"Option\":[{\"Name\":\"Administrator\",\"value\":\"false\"},{\"Name\":\"Client Administrator\",\"value\":\"true\"}]}"}

tried with this expression →
contains(Options, “Administrator”,“value”:“true”) && 'Admin' || (contains(Options, “Client Administrator”,“value”:“true”)) && 'Editor' || 'Viewer'

Result in JMESPath editor works perfectly fine and shows response →
“Editor”

But grafana throws error with escape characters
lvl=eror msg="Failed to extract role" logger=oauth.okta error="failed to search user info JSON response with provided path: \"contains(Options, \\\“Administrator\\\”,\\\“value\\\”:\\\“true\\\”) && 'Admin' || contains(Options, \\\“Client Administrator\\\”,\\\“value\\\”:\\\“true\\\”) && 'Editor' || 'Viewer'\": invalid character '\\\\' looking for beginning of value"

I am looking at this issue JSON keys with ':' character don't work in role_attribute_path · Issue #22986 · grafana/grafana · GitHub and thinking if I have a similar workaround for values instead of the keys

contains(Options, \"Administrator\",\"value\":\"true\") && ‘Admin’ || contains(Options, \"Client Administrator\",\"value\":\"true\") && ‘Editor’ || ‘Viewer’

1 Like