Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to parse JSON output
#1
I'm searching JIRA using REST API and trying to get subtask name (summary)

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

I need from this section in file to get summary (Remove user account in Local AD)

"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"
                            },
I tried:
import os
import csv
import urllib2
import argparse
import json
from bson import json_util

#password = str(sys.argv[1])



headers = {
    'Content-Type': 'application/json',
}

params = (
    ('jql', 'project="Technology" AND summary~"workspace creation*" AND issuetype="Task" AND status!="DONE"'),
)

response = requests.get('https://jira.corp.company.com/rest/api/2/search', headers=headers, params=params, auth=('user', 'pass;))

data = response.json()

for issue in data['issues']:
   print issue['fields']['subtasks']['summary']
i get:
Error:
print issue['fields']['subtasks']['summary'] TypeError: list indices must be integers, not str
same with:
Error:
for i in range (0, len (data['issues'])): print data['issues']['fields']['subtasks'][i]['fields']['summary'] TypeError: list indices must be integers, not str
Reply
#2
solved it:
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']
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  parse json field from csv file lebossejames 4 738 Nov-14-2023, 11:34 PM
Last Post: snippsat
  [split] Parse Nested JSON String in Python mmm07 4 1,529 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Trying to parse only 3 key values from json file cubangt 8 3,466 Jul-16-2022, 02:05 PM
Last Post: deanhystad
  How can i parse my output? ilknurg 4 1,573 Mar-16-2022, 03:27 PM
Last Post: snippsat
  How can i parse my output? ilknurg 20 3,355 Mar-10-2022, 02:19 PM
Last Post: ilknurg
  geojson to json --missing multiple row output yoshi 9 2,786 Mar-06-2022, 08:34 PM
Last Post: snippsat
  Problem to parse a json enigma619 3 2,378 Dec-04-2020, 08:16 AM
Last Post: enigma619
  How to parse JSON DIC? ogautier 4 2,237 Sep-15-2020, 06:03 PM
Last Post: ogautier
  Parse JSON multiple objects larkin_L 8 5,731 May-27-2020, 11:18 AM
Last Post: nuffink
  How can i parse a log file to JSON. menarcarlos 2 2,436 May-26-2020, 10:23 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020