Accessing and manipulating smart values as JSON data in Atlassian Automation Cloud

This article discusses how to effectively access and manipulate JSON data using smart values and JSON functions in Atlassian Automation Cloud. Whether you are working with data from an "Incoming webhook" or preparing to send data through the "Send web request" action, mastering these techniques is essential for optimising your automation rules.

 

To output the evaluated smart value expressions, use the "Log action" component. This writes the evaluated expression to the rule's "Audit log" and will be used throughout the article.

log action.png

 

When data is received through an "Incoming webhook" the smart value {{webhookData}} is automatically converted into a JSON object. However, sometimes the data in other smart values remains in a text/string format.

Below is an example JSON string used throughout this article.

{
   "message":  {
     "subject": "Test message",
     "participants": {
         "from": "from.test@example.com",
         "to": [ "to.test1@example.com", "to.test2@example.com" ]
     },
     "attachments": [
         {
            "filename": "attachment1.txt",
            "tags": [ "tag1", "tag2" ],
            "insights": [
                { "type": "quality", "value": "insight1 value" },
                { "type": "safety", "value": "insight2 value" },
                { "type": "safety", "value": "insight5a value" }
            ]
         },
         {
            "filename": "attachment2.txt",
            "tags": [ "tag3", "tag4" ],
            "insights": [
                { "type": "quality", "value": "insight3 value" },
                { "type": "safety", "value": "insight6a value" }
            ]
         }
     ]
   }
}

This string may originate from a smart value variable you defined or as part of a Jira issue's data. Below is an example of a Jira issue description containing this string in JSON format.

22.png

For convenience, here is the JSON in a single-line format (for you to copy and paste):

{"message":{"subject":"Test message","participants":{"from":"from.test@example.com","to":["to.test1@example.com","to.test2@example.com"]},"attachments":[{"filename":"attachment1.txt","tags":["tag1","tag2"],"insights":[{"type":"quality","value":"insight1 value"},{"type":"safety","value":"insight2 value"},{"type":"safety","value":"insight5a value"}]},{"filename":"attachment2.txt","tags":["tag3","tag4"],"insights":[{"type":"quality","value":"insight3 value"},{"type":"safety","value":"insight6a value"}]}]}}

 

 

Converting string to JSON

We can access that data using {{issue.description}}. To work with JSON data, we first convert the string to JSON using the jsonStringToObject() function.

Smart value expression:

{{jsonStringToObject(issue.description)}}

Evaluated output:

{message={subject=Test message, participants={from=from.test@example.com, to=[to.test1@example.com, to.test2@example.com]}, attachments=[{filename=attachment1.txt, tags=[tag1, tag2], insights=[{type=quality, value=insight1 value}, {type=safety, value=insight2 value}, {type=safety, value=insight5a value}]}, {filename=attachment2.txt, tags=[tag3, tag4], insights=[{type=quality, value=insight3 value}, {type=safety, value=insight6a value}]}]}}

 

 

Accessing JSON properties

Once the text/string is converted into a JSON object, you can access its data using dot notation.

Smart value expression:

{{jsonStringToObject(issue.description).message.participants.from}}

Evaluated output:

from.test@example.com

 

 

Accessing a single array

You can access an array even when it is nested within a structure.

Smart value expression:

{{jsonStringToObject(issue.description).message.participants.to}}

Evaluated output:

to.test1@example.com, to.test2@example.com

 


 

You can branch through the array and access each item individually.

33.png

Smart value expression (for branch):

{{jsonStringToObject(issue.description).message.participants.to}}

Smart value expression (for branched item):

PT: {{participantTo}}

Evaluated output:

PT: to.test1@example.com, PT: to.test2@example.com

 

 

Accessing multiple arrays

When accessing multiple arrays, they remain separate and are not merged into a single array.

Smart value expression (for branch):

{{jsonStringToObject(issue.description).message.attachments.tags}}

Evaluated output:

[tag1, tag2], [tag3, tag4]

 


 

You can branch through that array, but each item will be an array itself, rather than individual elements within those arrays.

44.png

Smart value expression (for branch):

{{jsonStringToObject(issue.description).message.attachments.tags}}

Smart value expression (for branched item):

TAG_ARRAY: {{tagArray}}

Evaluated output (looped twice):

TAG_ARRAY: tag3, tag4, TAG_ARRAY: tag1, tag2

These are two arrays and not four separate items.

 

 

Merging and accessing items from multiple arrays

If you want to merge multiple arrays into a single array, use the flatten function.

Smart value expression:

{{jsonStringToObject(issue.description).message.attachments.tags.flatten}}

Evaluated output:

tag1, tag2, tag3, tag4

 


 

You can now branch over it and access each individual item.

pa5.png

Smart value expression (for branch):

{{jsonStringToObject(issue.description).message.attachments.tags.flatten}}

Smart value expression (for branched item):

TAG_ARRAY: {{tagArray}}

Evaluated output (looped four times):

TAG_ARRAY: tag4, TAG_ARRAY: tag2, TAG_ARRAY: tag3, TAG_ARRAY: tag1

 


 

The same can be done for accessing objects in a nested array.

Smart value expression:

{{jsonStringToObject(issue.description).message.attachments.insights.flatten}}

Evaluated output:

{type=quality, value=insight1 value}, {type=safety, value=insight2 value}, {type=safety, value=insight5a value}, {type=quality, value=insight3 value}, {type=safety, value=insight6a value}

 


 

This enables you to branch through these objects and filter using a condition component.

pa1.png

Smart value expression (for branch):

{{jsonStringToObject(issue.description).message.attachments.insights.flatten}}

Added condition where type {{myInsightObject.type}} equals "safety".

pa2.png

Smart value expression (for branched item):

Safety: {{myInsightObject.value}}

Evaluated output:

Safety: insight2 value, Safety: insight5a value, Safety: insight6a value

 

 

Filtering without using branching

Currently, nested branching is not supported, and data within a branch cannot be shared outside of it, limiting its use for filtering.

To work around this limitation, you can filter data while creating the smart value variable using "Create variable." Let's name the variable safetyInsights.

Smart value expression (for branch):

{{#jsonStringToObject(issue.description).message.attachments.insights.flatten}}{{#if(equals(type, "safety"))}}{{value}}{{^last}},{{/}}{{/}}{{/}}

Evaluated output:

insight2 value,insight5a value,insight6a value

Ensure that you’re not adding unintended spaces in the expression, as this creates a single string where any spaces in your expression will be preserved.

This expression filters and returns only the items where the type is equal to "safety".

pa3.png

Reminder: Once created as a variable, it is no longer recognised as an array but as a string/text. To convert it back into an array for branching, use the split function.

Smart value expression (for branch):

{{safetyInsights.split(",")}}

pa4.png

You can now access each item within the branch using the defined variable name.

Smart value expression (for branched item):

Item:{{singleSafetyInsight}}

Evaluated output:

Item:insight5a value, Item:insight2 value, Item:insight6a value

 

Enjoy your rule creation!

2 comments

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.
March 8, 2025

Hi @Christopher 

Thank you for this article showing examples with the new jsonStringToObject() function.  I found that function helpful in scenarios such as accessing the Jira Product Discovery (JPD) date field attributes more easily.  Please consider adding the new flatten function to the smart value documentation, either in the text functions or JSON functions areas.

Kind regards,
Bill

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 8, 2025

Yeah, this is super-interesting! Looking at the Wayback Machine (because god forbid Atlassian publish changelogs for their products :-P), it looks like jsonStringToObject() was introduced sometime between Sept and Nov of last year?

I'm trying to think if the new flatten function would help with a Web Request to the Confluence API issue I'm having, but I'm thinking not:

User requested an automation that looks at a URL field in Jira, checks to see if it contains a Confluence link, and if so, tries to get the total number of viewers and comments on the page and put those numbers into dedicated fields for the purpose.

So I found an API call for unique viewers, and it works great.

But the footer and inline comments endpoints for the page only return root comments. So if people reply to a comment, those replies are not counted. There's a separate endpoints to get children of footer and inline comments, but I'd then end up looping through each of the root comments, and blurgh, we know that without Global Variables or Functions, there's no way to "accumulate" values.

OH! But this exploration led me to a DEPRECATED Get content comments  endpoint. Let's take a look at that. :-}

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events