Skip to content
Advertisement

How can I search a JSON file with given argument with Python?

I’m currently making an “info [argument]” command for discord.py bot that will search and return a value

So the user would say: “!Info bookshelf” the bot would look up “bookshelf” in the JSON file and find bookshelf = Shelf full of books and pull the value describing the bookshelf and send it in chat.

I’m new to coding so this would help so much! Thank you in advance <3

working on Python 3.9

Advertisement

Answer

Quite a simple solution: You would just take the arguments from the command (in this case “bookcase”), then parse it in to a search.

def lookup(args):
    look = data[args]
    return look
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement