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.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.