I have a python script that I want to print the JSON output to look something like this:
{
"authMode": "open",
"enabled": false,
"ipAssignmentMode": "NAT mode",
"name": "Unconfigured SSID 14",
"number": 13,
"perClientBandwidthLimitDown": 0,
"perClientBandwidthLimitUp": 0,
"splashPage": "None",
"ssidAdminAccessible": false
},
{
"authMode": "open",
"enabled": false,
"ipAssignmentMode": "NAT mode",
"name": "Unconfigured SSID 15",
"number": 14,
"perClientBandwidthLimitDown": 0,
"perClientBandwidthLimitUp": 0,
"splashPage": "None",
"ssidAdminAccessible": false
}
But my output looks like this instead:
{u'authMode': u'open',
u'enabled': False,
u'ipAssignmentMode': u'NAT mode',
u'name': u'Unconfigured SSID 14',
u'number': 13,
u'perClientBandwidthLimitDown': 0,
u'perClientBandwidthLimitUp': 0,
u'splashPage': u'None',
u'ssidAdminAccessible': False},
{u'authMode': u'open',
u'enabled': False,
u'ipAssignmentMode': u'NAT mode',
u'name': u'Unconfigured SSID 15',
u'number': 14,
u'perClientBandwidthLimitDown': 0,
u'perClientBandwidthLimitUp': 0,
u'splashPage': u'None',
u'ssidAdminAccessible': False}]
I feel like there is something simple I am missing. Here is my code:
url = "https://dashboard.meraki.com/api/v0/networks/%s/ssids" % NETWORKID
headers = {'X-Cisco-Meraki-API-Key': APIKEY}
r = requests.get(url, headers=headers, allow_redirects=True)
pprint (r.json())
I've found the easiest way to accomplish this is to use the json
module:
r = requests.get(url, headers=headers, allow_redirects=True)
import json
print(json.dumps(r.json(), indent=2))
Yes, this is a bit redundant in that you are deserializing then serializing again, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With