Forums

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

Automation: copy nested JSON custom field value

Paul Pasler
Atlassian Partner
March 13, 2025

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

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

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
March 13, 2025

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

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
March 13, 2025

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

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

 

Paul Pasler
Atlassian Partner
March 18, 2025

@Bill Sheboy thanks again for spending time on this!

It's a shame, that there seems to be no function to transform the object to a valid JSON with smart values. Are you aware of any feature request for this?

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 18, 2025

The only suggestions I recall in this area were to support "other formats of JSON" in rule actions...although I was unclear what was being asked for in those ;^)

Please give the iterator a try and let me know if you run into challenges.  Thanks!

Like Paul Pasler likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events