I am new to python and i need some help to achive my output format.
i have response.json file output (getting this output from some other depended service.
Note: when i checked the type of this file its showing as list)
import json
results = json.load(open(“response.text”))
print(type(results))
output = <class ‘list’>
[
[
"############################## CHECKING FLOW ####################################",
" 10.211.131.19 [MUM] ---> 10.221.131.19 [DEL] on Port: 22, Protocol: tcp",
"############################## CHECKING FLOW ####################################"
],
[
{
"HUNTER OUTPUT FOR MUM FROM ACL": [
"",
"Source Address: 10.211.131.192/255.255.255.192",
"Destination Address: 10.160.0.0/255.255.128.0,10.161.0.0/255.255.0.0,10.162.0.0/255.255.0.0,10.163.0.0/255.255.128.0,10.164.160.0/255.255.224.0,10.165.128.0/255.255.192.0,10.166.128.0/255.255.128.0,10.170.0.0/255.255.128.0,10.172.0.0/255.255.128.0,10.172.160.0/255.255.224.0,10.173.0.0/255.255.0.0,10.176.0.0/255.254.0.0,10.178.0.0/255.255.192.0,10.178.200.0/255.255.248.0,10.178.208.0/255.255.240.0,10.180.0.0/255.252.0.0,10.184.0.0/255.255.0.0,10.208.192.0/255.255.192.0,10.212.0.0/255.255.0.0,10.213.0.0/255.255.128.0,10.214.128.0/255.255.192.0,10.218.0.0/255.254.0.0,10.220.0.0/255.255.0.0,10.224.0.0/255.255.0.0,10.226.0.0/255.254.0.0,10.235.0.0/255.255.224.0,10.244.0.0/255.254.0.0,10.247.0.0/255.255.0.0",
"Destination Port: 22,
"Source Port: 0",
"Protocol: tcp",
"Application: ",
"Wildcard: False",
"Action: PERMIT"
]
},
{
"HUNTER OUTPUT FOR DEL TO ACL": [
"",
"Source Address: 10.0.132.128/255.255.255.192,10.10.132.128/255.255.255.192,10.18.132.128/255.255.255.192,10.44.132.128/255.255.255.192,10.161.133.0/255.255.255.192,10.162.133.0/255.255.255.192,10.173.132.128/255.255.255.192,10.180.133.192/255.255.255.192,10.182.133.192/255.255.255.192,10.186.132.192/255.255.255.192,10.188.132.192/255.255.255.192,10.211.131.192/255.255.255.192,10.218.131.192/255.255.255.192,10.219.131.192/255.255.255.192,10.226.128.0/255.255.255.192,10.227.130.192/255.255.255.192,10.244.132.128/255.255.255.192",
"Destination Address: 10.160.0.0/255.255.128.0,10.164.160.0/255.255.224.0,10.172.160.0/255.255.224.0,10.212.0.0/255.255.0.0",
"Destination Port: 22,
"Source Port: 0",
"Protocol: tcp",
"Application: ",
"Wildcard: False",
"Action: PERMIT"
]
}
]
]
i want to get only output as below from the above response.json file
"############################## CHECKING FLOW ####################################",
" 10.211.131.19 [MUM] ---> 10.221.131.19 [DEL] on Port: 22, Protocol: tcp",
"############################## CHECKING FLOW ####################################"
"HUNTER OUTPUT FOR MUM FROM ACL":
"Action: PERMIT"
"HUNTER OUTPUT FOR DEL TO ACL"
"Action: PERMIT"
How to get output lile this ?
I tried it in below way
import json
from pprint import pprint
results = json.load(open("response.text"))
pprint(list(enumerate(results)))
for line in results:
for l in line:
pprint(l)
but output is cominng in this format
sivarama.krishna@sivaram-ltm3m98 hunter-gus-tools % python3 test.py
0
['############################## CHECKING FLOW '
'####################################',
' 10.211.131.19 [MUM] ---> 10.212.131.19 [DEL] on Port: 22, Protocol: tcp',
'############################## CHECKING FLOW '
'####################################']
1
[{'HUNTER OUTPUT FOR MUM FROM ACL': ['',
'Source Address: '
'10.211.131.192/255.255.255.192',
'Destination Address: '
'10.160.0.0/255.255.128.0,10.161.0.0/255.255.0.0,10.162.0.0/255.255.0.0,10.163.0.0/255.255.128.0,10.164.160.0/255.255.224.0,10.165.128.0/255.255.192.0,10.166.128.0/255.255.128.0,10.170.0.0/255.255.128.0,10.172.0.0/255.255.128.0,10.172.160.0/255.255.224.0,10.173.0.0/255.255.0.0,10.176.0.0/255.254.0.0,10.178.0.0/255.255.192.0,10.178.200.0/255.255.248.0,10.178.208.0/255.255.240.0,10.180.0.0/255.252.0.0,10.184.0.0/255.255.0.0,10.208.192.0/255.255.192.0,10.212.0.0/255.255.0.0,10.213.0.0/255.255.128.0,10.214.128.0/255.255.192.0,10.218.0.0/255.254.0.0,10.220.0.0/255.255.0.0,10.224.0.0/255.255.0.0,10.226.0.0/255.254.0.0,10.235.0.0/255.255.224.0,10.244.0.0/255.254.0.0,10.247.0.0/255.255.0.0',
'Destination Port: '
'22,
'Source Port: 0',
'Protocol: tcp',
'Application: ',
'Wildcard: False',
'Action: PERMIT']},
{'HUNTER OUTPUT FOR DEL TO ACL': ['',
'Source Address: '
'10.0.132.128/255.255.255.192,10.10.132.128/255.255.255.192,10.18.132.128/255.255.255.192,10.44.132.128/255.255.255.192,10.161.133.0/255.255.255.192,10.162.133.0/255.255.255.192,10.173.132.128/255.255.255.192,10.180.133.192/255.255.255.192,10.182.133.192/255.255.255.192,10.186.132.192/255.255.255.192,10.188.132.192/255.255.255.192,10.211.131.192/255.255.255.192,10.218.131.192/255.255.255.192,10.219.131.192/255.255.255.192,10.226.128.0/255.255.255.192,10.227.130.192/255.255.255.192,10.244.132.128/255.255.255.192',
'Destination Address: '
'10.160.0.0/255.255.128.0,10.164.160.0/255.255.224.0,10.172.160.0/255.255.224.0,10.212.0.0/255.255.0.0',
'Destination Port: '
'22,
'Source Port: 0',
'Protocol: tcp',
'Application: ',
'Wildcard: False',
'Action: PERMIT']}]