Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pulling out certain values passed in through a string

I need to pull out certain values of a string.

Part of python string is

{"expand":"schema,names","startAt":0,"total":1244,"issues":[{"id":"1","self":"xxxxxxxx","key":"UKTEST-33982","fields":{"Test":"Test1","priority":{"name":"Critical","id":"10000"}}},{"id":"2","self":"xxxxxxxx","key":"UKTEST-10674","fields":{"Test":"Test2","priority":{"name":"medium","id":"10001"}}}]}
I require to pull out the key field "UKTEST-33982" and "UKTEST-10674" and so forth.

Here is my code so far (ive taken out the username and password):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import requests
from requests.structures import CaseInsensitiveDict


url = "https://xxxx.com/xxxxxx/rest/api/2/search?xxxx=project=UKTEST"


r = requests.get(url, auth=(username, password))
packages_json = r.json ()
packages_str = json.dumps(packages_json)

print(packages_str)

I’ve had a look through the documentation and can’t find what function to use.

>Solution :

if you want to pull out all the ["issues"][n]["key"] you can do:

json = {"expand":"schema,names","startAt":0,"total":1244,"issues":[{"id":"1","self":"xxxxxxxx","key":"UKTEST-33982","fields":{"Test":"Test1","priority":{"name":"Critical","id":"10000"}}},{"id":"2","self":"xxxxxxxx","key":"UKTEST-10674","fields":{"Test":"Test2","priority":{"name":"medium","id":"10001"}}}]}
keys = [issue["key"] for issue in json["issues"]]
print(keys)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading