Forums

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

Jira automation json dot notation syntax

Jonathan Porta
Contributor
October 25, 2024

Hello all, 

I use Jira automation for a long time but it is quite the first time I have to integrate an API call in my automation rule.

The context is the following: From a JSM ticket, I want two of the organization detail fields values to be copied to a custom field in an internal project ticket created automatically.

So, I was able to authentify, I was able to configure the API call, I got a 200 response with a correct payload.

My question is more about the dot notation. I'm used to XPath3 but I cannot transfer that knowledge to this strange syntax...

This is my payload:

{ "id": "24", "name": "MY CLIENT", "details": [ { "id": "104", "name": "Key client", "type": { "name": "SELECT", "options": [ "Yes", "No" ] }, "values": [ "Yes" ], "configuration": { "position": 0 } }, { "id": "105", "name": "Client at risk", "type": { "name": "SELECT", "options": [ "Yes", "No" ] }, "values": [ "No" ], "configuration": { "position": 1 } } ] }

 Quite easy, as I have two properties listed in details, so I can access the first one like 

{{webResponses.last.body.details.first.values.first}}

and the other one with

{{webResponses.last.body.details.last.values.first}}

Ok that's cool, but how would I do it if I have more than two? Is there a way to enter specific node like in Xpath? Or at least an indexer? I don't know something like

 

{{webResponses.last.body.details[0].values[0]}}

Is there another way to parse the result?

 

Thanks for your help!

1 answer

1 accepted

4 votes
Answer accepted
Matthias Gaiser _K15t_
Community Champion
October 25, 2024 edited

Hi @Jonathan Porta

I'd recommend to check out the documentation about working with lists in smart values. This lists all the methods which are possible on multi values like .get(0).

EDIT: Or with your example:

{{webResponses.last.body.details.get(0).values.get(0)}}

Cheers,
Matthias.

Jonathan Porta
Contributor
October 25, 2024

Wow nice, it was exactly what I was looking for!

 

Ok so I can have index-based accessors, that's already nice. Is there a way to have something like "the element in the list where the name is XXX"?

I'm not that sure it would work with combined functions

{{webResponses.last.body.details}}XXX-{{.}}{{/}}{{/}}.values.get(0)}}

 

Matthias Gaiser _K15t_
Community Champion
October 25, 2024

@Jonathan Porta, you made me curious to find that out.

And yes, there's a way like that. I have an example here which works on a list of users. Let's assume, we have these users in the customfield_11098:

[
{
"displayName": "Jaron",
"emailAddress": "jaron@example.com"
},
{
"displayName": "Timon",
"emailAddress": "timon@example.com"
},
{
"displayName": "Mona",
"emailAddress": "mona@example.com"
}
]

If we then use this smart value to filter them based on the displayName:

{{#issue.customfield_11098}} {{#if (equals(displayName, "Timon"))}} {{emailAddress}} {{/}} {{/}}

Then we get this result:

timon@example.com

If you want to learn more about conditions, check out these docs.

Like Jonathan Porta likes this
Jonathan Porta
Contributor
October 25, 2024

WOW! I really don't know who is at the origin of the counter-intuitive syntax, but you are now basically a hero to me!

Thank you very much!

Have a incredibly beautiful week-end!

Like Matthias Gaiser _K15t_ likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
atlassian, mindful member, mindful member badge, atlassian community, community kudos, community giveaway, atlassian swag, community values, empathy and kindness, badge challenge, atlassian learning, community engagement, swag giveaway

Earn a Badge, Win a Prize 🎁

Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!

Start here
AUG Leaders

Atlassian Community Events