This may look like a basic questions, but here is what I am trying to do:
This is my current JSON structure:
{
"11": {
"14": [
"704712637988077XXX"
],
"16": [
"704712637988077XXX"
],
"17": [
"704712637988077XXX"
]
}
}
Whereas 11
stands for the month, 14
/16
and 17
for a date and the number inside the list is a user ID. What I am trying to achieve is that my code checks if the ID of the user exists somewhere, taking into account all the dates or months saved in the JSON. (There could be more months and dates!)
Is there any function that takes care of this?
I checked the following posts on this:
- How to parse json to get all values of a specific key within an array?
- Check if a value exists in a json file with python
- Check if key exists and iterate the JSON array using Python
and much more but I am kind of stuck.
What I tried to do:
str(ctx.author.id) in any(data[str(month)][str(day)]) # Should return True or False but is somehow inconsistent
str(ctx.author.id) and any(data[str(month)][str(day)]) == True # Does not make sense at all, I guess
str(ctx.author.id) in any(data[str(month)][str(day)]).__str__() # Convert everything and check for the value
data
is of course the JSON I open, month
and day
are converted inputs of the user that are later displayed as 11
for the month and 14, 16, 17...
as days in the JSON.