Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
json and python
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.
Gribouillis and buran like this post
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs


Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020