Skip to content
Advertisement

Is there any way to search through a JSON object for a value? [closed]

I’m currently working on a ROBLOX Integrated discord bot with discord.py and have stumbled into an issue with checking if the user is in a group. I have already got a table of all groups and ranks, but have no clue how to iterate through it. The JSON structure is similar to as follows:

JavaScript

In a real example, there would be more than just two groups but I was wondering if there was any way to iterate through and check if the group ID is equal to 1 and then get the role associated with the group? I couldn’t find a solution anywhere else.

Advertisement

Answer

So basically, data is a key and the bracket block is a value. That value is a list of dictionaries and the group key corresponds to another dictionary this one containing the id.

So if the json is stored in a variable called x then doing

JavaScript

will get one of them. A loop would be something like

JavaScript

Hopefully this helps. The json would need to be correct though!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement