Apr-06-2023, 11:15 AM
(Mar-23-2023, 08:34 PM)deanhystad Wrote: Your json file is wrong.
The thing to remember is you are never using json. You are using Python dictionaries and lists. json is only used to read/write information to a file. It is no relevant.
Output:{ "person": [ { <-- This does not belong {"id": "1", "name": "Geroge" "status": "unsent" }, {"id": "2", "name": "Tim" "status": "unsent" } ] }
Load the corrected json file. This produces a dictionary that looks like this:
people = {"person":[{"id":1, "name": "George", "status": "unsent"}, {"id":2, "name": "Tim", "status": "unsent"}]}
Create a list of all person objects that are not sent. I would do this with a comprehension.
unsent = [person for person in people["person"] if person.status == "unsent"]
Randomly select a person from the unsent list and change status to "sent"
dump people to a json file.
I finally managed go get it running. Thanks for your tip with the comprehension