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

parse json results into a list

Franco Genga
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 18, 2023

Hi, I designed an automation that sends a web request and this is the Json I receive:

{datos=[{field1=abc, number=1234}, {field1=abcd, number=4567}], response={description=null, responseCode=200, responseId=null}}

I created a smart value to read the response and get some data: {{webResponse.body.MetodoPagoOut.datos.number}} and I get this string: 1234, 4567

Is there any way to convert the results into a list? I need to extract each pair of values to create an object, using a branch perhaps.

Thanks,

Franco

2 answers

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.
August 18, 2023

Hi @Franco Genga -- Welcome to the Atlassian Community!

Please try using the split() function to split the text into a list: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#split-String-separator-

If that does not help, please post images of your complete rule and the audit log details showing the rule execution.  Those will provide context for the community to offer help.  Thanks!

Kind regards,
Bill

Franco Genga
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 22, 2023

Hi Bill! Thanks for that response.

I reviewed all the docs and made a lot of tests using smart values for text fields but I still can't resolve it.

What I'm trying to accomplish is to convert this string: "1234, 4567" (now it has only 2 numbers separated by a comma but it could be more in the future) into a collection, so I can use advanced branches, in order to use it as a loop...is it possible? Has anyone could ever resolve this?

Thanks!

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.
August 22, 2023

This will work using split(",")

Would you please post images of your rule where this does not work as you expect, including images of the action, condition, and branch details, and of the audit log details showing the rule execution?

Please note: sometimes parsing web request responses results in an array rather than a list.  There are solutions for that, but let's first see what your rule looks like before investigating that possibility.

0 votes
David Foote
Contributor
September 7, 2023

You can do it via the split(", ") string function others have mentioned.

Something that I struggled with was how to access the data in the newly created list. If you are using the # loop construct, you can access it via {{.}}

So, in your example, if you wanted to loop through the list created by split() it would look like:

{{#webResponse.body.MetodoPagoOut.datos.number.split(", ")}}
{{.}}
{{/}}

And the output would be

1234
4567

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events