-3

I am calling an API and getting response like below and want to parse using python

{ "OutputParameters": { "@xmlns": "http://.com", "@xmlns:xsi": "http://.com", "P_OUT_HDR": { "A": "5", "B": "1", "C": "1", "D": "1", "E": "SUCCESS", "F": null }, "P_OUT_TBL": { "P_OUT_TBL_ITEM": [ {"Z": "4757", "X": "2934", "Y": "XYZ", "G": "ABC", "P": "No", "K": "TEST", "L": "Test", "M": null, "N": "2021-02-23", "O": "30", "P": "24.99", "J": "2021-02-23", "T": "XYZ", "U": "XYZ" }, {"Z": "4757", "X": "2934", "Y": "XYZ", "G": "ABC", "P": "No", "K": "TEST", "L": "Test", "M": null, "N": "2021-02-23", "O": "30", "P": "24.99", "J": "2021-02-23", "T": "XYZ", "U": "XYZ" } ] } } }

APS
  • 7
  • 5
  • 4
    What have you tried? Why did it not work? Which errors did you experience? In its current form, your question is not a good match for stackoverflow.com and will likely be voted closed with "need more detail" as reason – Morten Jensen Feb 24 '21 at 13:48
  • 1
    How are you calling an API? If with `requests` lib, then `r.json()` (where r is Response object returned by `requests.get`) automatically parses the result into Python object... – h4z3 Feb 24 '21 at 13:50
  • I agree with both @MortenJensen and h4z3 here. You may want to take a look at the following so answer: https://stackoverflow.com/questions/16877422/whats-the-best-way-to-parse-a-json-response-from-the-requests-library – disooqi Feb 24 '21 at 13:58

1 Answers1

0

I'm guessing you're using the requests library. If so, you can get the JSON as dictionary as follows:

r = requests.get( ... )
result = r.json()
ap1997
  • 173
  • 5