Software Development Kit (SDK) and API Discussions

Highlighted

Re: How to get result from NMSDK in json format or set content type to application/json

Initially you said, you want Application/JSON. May I know you need JSON or Application/JSON? 

 

If you need only JSON, you can not convert XML to JSON but from XML to Dict. Though there is work around to convert using Application/JSON using Response which is usable in Flask. 

If you just need JSON in order to access Dict key/values then xmltodict should work for you. You can use this way. 

 

obj = xmltodict.parse(xo.sprintf())
jd = json.dumps(obj)
jl = json.loads(jd)


if xo.results_status() == "failed":
reason = xo.results_reason()
print ("Failure: %s" %reason)
else:

for h in jl["results"]["attributes-list"]["aggr-attributes"]:
if int(h["aggr-space-attributes"]["percent-used-capacity"]) > 80:
print (h["aggregate-name"], readable_size(int(h["aggr-space-attributes"]["size-total"])), readable_size(int(h["aggr-space-attributes"]["size-used"])), readable_size(int(h["aggr-space-attributes"]["size-available"])), h["aggr-space-attributes"]["percent-used-capacity"])
else:
pass


@neha_T wrote:

yes, now it is giving json output, but only class instance

when i try to get data also it is giving instance details only.

 

example:

obj = xmltodict.parse(xo.sprintf())
jd = json.dumps(obj)
jl = json.loads(jd)
a = Response(jl, content_type='application/json')
#pprint.pprint(dir(a))

pprint.pprint(a)--> <Response likely-streamed [200 OK]>
print a.get_json-->  <bound method Response.get_json of <Response likely-streamed [200 OK]>>
print a.is_json---> True
print a._get_data_for_json--> <bound method Response._get_data_for_json of <Response likely-streamed [200 OK]>>
 
 
what i want is json data.

 

 

 

Re: How to get result from NMSDK in json format or set content type to application/json

thanks @gaurav_verma 

it is working fine.

Re: How to get result from NMSDK in json format or set content type to application/json

Can you please close this by accepting the solution. 

Forums