Ask a Question

How can i find a specific data constellation in an array

manfredt
Occasional Contributor

How can i find a specific data constellation in an array

Hi,

i'm trying to verify a change of roles for a user in a report. The report is an array of [user,[roles]]. Which means every user is one entry in the array and next to the user information is an array of the roles of the user.

I know the username and the role that i added or removed. I can search the array for the username ($[*][?(@.name=='username')] which returns the complete user information without the roles. Similar i can search for the role and that returns the role information (several times) but without the user information.

 

Can i combine those two to find the one item that has the correct username and role? Or change the query so that it returns the roles as well? Or is there a way to identify the position of that user in the list and then query that specific entry in the array?

 

Thanks in advance

2 REPLIES 2
richie
Community Hero

Hey @manfredt,

Can you provide an example payload so people can see the structure/hierarchy please? This will help in answering your question.

Cheers,

Rich


if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
manfredt
Occasional Contributor

Hi @richie 

Here is an example of the structure (better formatted in the attachment)

[
{"user" : {
              "id" : "1",
              "name" : "user1"},
"roles" : [{

             "id" : "a",
             "roleName" : "role a"}
             ]
},
{"user" : {
              "id" : "2",
              "name" : "user2"},
"roles" : [{
             "id" : "a",
             "roleName" : "role a",},
             {
             "id" : "b",
             "roleName" : "role b"}
             ]
}
]

cancel
Showing results for 
Search instead for 
Did you mean: