Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
facing issue in python
#1
i have below json file. When i amtrying to pull sid and type from applicationRoles, i am able to pull only first entry i.e.sid=123 and type=BC but i need both entries
{
"applicationgroup":[
{
"name":"test"
"applicationRoles":[
{
"sid":123
"type":'BC'
},
{
"sid":234
"type":'adBC'
}
],
"type":"tttt"
}
]
}
my code: -
import sys
import json
import csv
with open('test.json','r') as f:
json_data=json.data(f,strict=false)
with open('test.csv','w') as out:
csv_write=csv.writer(out)
csv_write.writerow(["name","sid","type"])
for json_d in json_data["applicationgroups"]:
row_array=[]
try:
row_array.append(json_d["name"])
except KeyError:
row_array.append(")
try:
row_array.append(json_d["applicationRoles"][0]["sid"])
except (KeyError,TypeError):
row_array.append(")
try:
row_array.append(json_d["applicationRoles"][0]["type"])
except (KeyError,TypeError):
row_array.append(")
except TypeError:
row_array.append(")
csv_write.writerow(row_array)
out.close()
Reply


Messages In This Thread
facing issue in python - by rajrishi990 - Nov-27-2019, 04:24 PM
RE: facing issue in python - by buran - Nov-27-2019, 04:25 PM
RE: facing issue in python - by rajrishi990 - Nov-27-2019, 04:29 PM
RE: facing issue in python - by snippsat - Nov-27-2019, 05:25 PM
RE: facing issue in python - by rajrishi990 - Nov-27-2019, 05:44 PM
RE: facing issue in python - by rajrishi990 - Nov-28-2019, 04:22 AM
RE: facing issue in python - by micseydel - Dec-05-2019, 11:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Facing issue in python regex newline match Shr 6 1,476 Oct-25-2023, 09:42 AM
Last Post: Shr
  Facing problem with Pycharm - Not getting the expected output amortal03 1 893 Sep-09-2022, 05:44 PM
Last Post: Yoriz
  Facing Problem while opening a file through command prompt vlearner 4 1,989 Jan-30-2022, 08:10 AM
Last Post: snippsat
  Facing error while executing below Python code ramu4651 1 5,823 Jan-26-2021, 06:40 PM
Last Post: ibreeden
  I want to create small multiples grouped bar plot, and facing some aesthetics issuess dev_kaur 0 1,652 Dec-05-2020, 08:49 AM
Last Post: dev_kaur
  Facing issue while saving workbook Abhisht 3 5,681 Aug-19-2020, 11:44 AM
Last Post: Larz60+
  Facing issue with pyautogui program after PC upgrade Utkarsh29 2 2,999 Jul-15-2019, 05:20 PM
Last Post: Utkarsh29
  Facing an issue in doing 'unittest.installHandler()' which will send 'stop' signal to hmarne 3 4,217 Jan-24-2017, 05:03 PM
Last Post: buran

Forum Jump:

User Panel Messages

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