Forums

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

How to convert webresponse to text

Sergei Gridnevskii
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.
May 4, 2022

I am using Automation for Jira to request information using a web request. It returns a JSON that is in fact not really useful:

{latest=2022-05-03T15:16:30+00:00, employees={598={id=598, action=Inserted, lastChanged=2022-05-02T18:19:51+00:00}, 602={id=602, action=Inserted, lastChanged=2022-05-02T18:19:51+00:00}, 603={id=603, action=Inserted, lastChanged=2022-05-03T15:16:30+00:00}}}


In fact I need 3 ids from this JSON. But objects in employees are not a part of array, it is a hash map. When I use webresponse.body.employees I have no idea how to extract ids.

A good solution would be to convert employees to string, use split function and convert it to array. E.g.

{{webResponse.body.employees.asText.split("={id=")}}

however this does not work and returns empty text.

Are there any ideas? 

 

1 answer

2 votes
Sergei Gridnevskii
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.
May 4, 2022

This works

{{webResponse.body.employees."603"}}

It returns 

{id=603, action=Inserted, lastChanged=2022-05-03T15:16:30+00:00}

However I do not know "603" for every response, today it is 603, tomorrow it will be 620. 

It would be nice to have something like a list of keys of a json object

{{webResponse.body.employees.keys}}

that I can iterate through.

Suggest an answer

Log in or Sign up to answer