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?
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
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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--
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.