Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Automation: copy nested JSON custom field value

Paul Pasler
Atlassian Partner
yesterday at 10:35 AM

Hi there,

I am having a hard time copying a nested JSON value from one issue to another.

The field value looks like this

{
options: [
[{"id": "0", "name": "Option 1"}],
[{"id": "2", "name": "Option 2"}, {"id": "3", "name": "Option 3"}],
[{"id": "4", "name": "Option 4"}
]
}

The number of levels (inner list) and options (id, name) can vary.

I simply want to copy the whole value, but when I do something like this

{
"fields": {
"Foo bar": {{issue.fields."Foo bar"}}
}
}
{
"fields": {
"Foo bar": { options: {{issue.fields."Foo bar".options}} }
}
}

I get this error: "Error while parsing additional fields. Not valid JSON."

 

Is it possible to correctly handle nested objects with smart values in automation?

1 answer

1 vote
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.
yesterday at 11:01 AM

Hi @Paul Pasler 

As you are trying to set the field with advanced edit with JSON, please try adding the function jsonEncode() to the end:

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#jsonEncode--

This may require some fine-tuning, so I recommend saving the entire update expression in a Created Variable and writing it to the audit log before the update.  That will help to diagnose if the result is valid JSON.

Kind regards,
Bill

Paul Pasler
Atlassian Partner
yesterday at 11:58 AM

Thanks Bill!

Actually it looks like I need the direct opposite ("jsonParse"). I thinks the value is provided as a string, when it should be a JSON object (or list of lists of objects).

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.
yesterday at 1:12 PM

I believe when the text is passed in the advanced edit it will be parsed into JSON before it is validated. 

Did you try writing the expression to the audit log, and then perhaps copy-and-pasting the result into a text editor to learn if it is valid JSON?

 

Also, when you need to convert text to JSON for other uses, the function jsonStringToObject() will help: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#jsonStringToObject--

Like • Paul Pasler likes this
Paul Pasler
Atlassian Partner
yesterday at 10:47 PM edited

Logging the original field value shows, that the value is an Object.

{selection=[[{id=0, name=Option 1}] ...]}

It's not a string. Furthermore without quotes and "=" instead of ":", not valid JSON.

I somehow need to transform it to this

{"selection": [[{"id": "0", "name": "Option 1"}] ...]}

Didn't find a solution so far.

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.
7 hours ago

To do that, I believe you will need to use an iterator to build the JSON expression yourself, iterating over the field value's objects.  However if that value is text representing the object, you could instead:

  • use a match() or substringBetween() function to strip off the outer information
  • split() the result on the right-square bracket to convert to a list
  • use text functions to extract each element to build the JSON

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.

Learn more
AUG Leaders

Upcoming Jira Events