Home > Back-end >  how to make a json on a json
how to make a json on a json

Time:12-17

hi I have a question I want to create a bot that has luck wheel and the prizes is in a json file but the problem is that the bot will be in many servers.. so i wanted to know how to make like this :

{
  "example_of_server_id":{
                           "legandary luck":["first leg prize","second leg prize", "third leg prize],
                           "epic luck":["first epic prize", "second epic prize", "third epic prize"],
                           "normal luck":["first normal prize", "second normal prize", "third normal prize],
                           "bad luck":["first bad prize", "second bad prize", "third bad prize"]
}

and the bot do this all times that he enter in servers but without the "first normal prize" and all things like he will do like: a [] after the bad and normal and epic and leg luck thx ! :D

CodePudding user response:

I assume you use Python.

You can use the json library (beginner friendly version).

It will be something like this

import json

object_a = {"legandary luck": ["first leg prize", "second leg prize", "third leg prize"],
            "epic luck": ["first epic prize", "second epic prize", "third epic prize"],
            "normal luck": ["first normal prize", "second normal prize", "third normal prize"],
            "bad luck": ["first bad prize", "second bad prize", "third bad prize"]}
json_a = json.dumps(object_a)

object_b = {"server_id": json_a}
json_b = json.dumps(object_b)
print(json_b)

However, the better approach is to simply just put object_a into object_b directly so that you do not have to dumps them twice.

object_b = {"server_id": object_a}
json_b = json.dumps(object_b)
  • Related