Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automation: Navigating complex JSON objects using "smart values"

Paulo Sebastião July 24, 2024

Hi all,

Consider the following JSON:

 

{

"key": "user_details",
"value": [
{
"key": "user1@example.com",
"value": {
"email": "user1@example.com",
"accountId": "account-id-1",
"avatar": "https://avatar-management--avatars.example.com/avatar1.png",
"slackUserId": "slack-id-1"
}
},
{
"key": "user2@example.com",
"value": {
"email": "user2@example.com",
"accountId": "account-id-2",
"avatar": "https://avatar-management--avatars.example.com/avatar2.png",
"slackUserId": "slack-id-2"
}
},
{
"key": "user3@example.com",
"value": {
"email": "user3@example.com",
"accountId": "account-id-3",
"avatar": "https://avatar-management--avatars.example.com/avatar3.png",
"slackUserId": "slack-id-3"

}
]
}

I get this from an JIRA Project property that I've set programatically. It contains some user details about the users who work on my project. I want to use in JIRA Automation, to be able to send messages directly to the users or posting comments on JIRA cards using their accountId, etc. You get the drill.

Given I have the variable email, how do I build a smart value "query" that can give me the slackUserId for the the user with given email?

Is this even possible in automation? 

Disclaimer: I can structure the object in whatever way I want. Just thought that key-value pair was cute.

1 answer

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 25, 2024 edited

Hi @Paulo Sebastião 

To save you some automation, experimentation time...

Once inside of an iterator (e.g., looping over your JSON) data from outside (e.g., your variable email) cannot be accessed.

The workaround is to use your variable and knowledge of the structure to build a dynamic regular expression, and then pass that to the inline iterator with the match() function, finally parsing the data needed using text functions.  As a brief example:

  • create variable, perhaps named varRegEx, as described above
.*(\"email\": \"{{email}}\".*)
  • split the data on a known location, and use the inline form of iteration for the search
{{yourData.replace("\n"," ").split("\"key\":").match(varRegEx)}}
  • add text functions to the result to parse out the Slack ID

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events