-1

whole file is here:https://1drv.ms/u/s!AizscpxS0QM4hJpFPnbeAexYPwYu9Q

I want from this part:

"subtasks": [
                    {
                        "fields": {
                            "issuetype": {
                                "avatarId": 10316,
                                "description": "The sub-task of the issue",
                                "iconUrl": "https://jira.corp.company.com/secure/viewavatar?size=xsmall&avatarId=10316&avatarType=issuetype",
                                "id": "10101",
                                "name": "Sub-task",
                                "self": "https://jira.corp.company.com/rest/api/2/issuetype/10101",
                                "subtask": true
                            },
                            "priority": {
                                "iconUrl": "https://jira.corp.company.com/images/icons/priorities/medium.svg",
                                "id": "3",
                                "name": "Medium",
                                "self": "https://jira.corp.company.com/rest/api/2/priority/3"
                            },
                            "status": {
                                "description": "",
                                "iconUrl": "https://jira.corp.company.com/",
                                "id": "10000",
                                "name": "Backlog",
                                "self": "https://jira.corp.company.com/rest/api/2/status/10000",
                                "statusCategory": {
                                    "colorName": "blue-gray",
                                    "id": 2,
                                    "key": "new",
                                    "name": "To Do",
                                    "self": "https://jira.corp.company.com/rest/api/2/statuscategory/2"
                                }
                            },
                            "summary": "Remove user account in Local AD"
                            },

to extract "Remove user account in Local AD" (summary field)

So far i have this code:

data = json.load(open(1.json))


for issue in data['issues']:
   print issue['fields']['subtasks']

and getting section above, how to get only summary value ?

if i add:

for issue in data['issues']:
   print issue['fields']['subtasks']['summary']

i get:

 print issue['fields']['subtasks']['summary']
TypeError: list indices must be integers, not str

same with:

    for i in range (0, len (data['issues'])):
       print data['issues']['fields']['subtasks'][i]['fields']['summary']
TypeError: list indices must be integers, not str
2
  • Subtasks is a list, loop through it and print item['summary'] for each item in the list. Although from this example it looks like it would be item['fields']['summary'] Commented Apr 19, 2018 at 16:07
  • item['fields']['summary'] gives summary of main issues, not subtasks summary (Remove user account in Local AD) Commented Apr 19, 2018 at 18:31

2 Answers 2

1

Ah, subtasks is the key, but the item is a list!

So it will be issue['fields']['subtasks'][0]['summary'] what you are looking for.

Sign up to request clarification or add additional context in comments.

5 Comments

print issue['fields']['subtasks'][0]['summary'] KeyError: 'summary'
I had a closer look: try print issue['fields']['subtasks'][0]['fields']['summary'] It should work
already tried that: print issue['fields']['subtasks'][0]['fields']['summary'] IndexError: list index out of range
I think is better using the method .get() issue.get('fields').get(...)
print issue.get("fields").get("subtasks").get("summary") AttributeError: 'list' object has no attribute 'get'
0

thanks to @nawarkhede

for issue in data['issues']:
  for subtask in issue['fields']['subtasks']:
    if subtask['fields']['summary'] == 'The specified directory could not be found in the specified region.-traider':
      print subtask['fields']['summary']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.