Python Forum

Full Version: json and python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a problem.
I receive a response in JSON format from a web REST API (which returns me all the values related to the invoices of a shopping center)
Now from all the key-value pairs I have to take all the values with key "total_ invoice" (it is a field that refers to the amount including VAT) and put them in a variable so that we can then add them all and have an overall TOTAL.

p.s I tried to use the module (python) -json- but it converts everything to dictionaries (which how do I manage?).
I mean dictionaries .. in the sense that for each "invoice instance" I create a different dictionary (so I find myself a big dictionary called "all documents" and inside a lot of dictionaries for how many single invoices are

Way out?
It isn't really clear what problem you're having. Using the json module to turn the JSON from the response into Python data structures like dictionaries is the correct way to go since you can manipulate them easily.

Give us more details about what you're trying and what isn't working, showing sample JSON, code and errors if appropriate.
1. if you are using requests you can use convenient Response.json() method
2. show us what you get (as JSON or dict of dicts) so that we can advise how to parse it. Use dummy data.