how to get raw data for a nested key in my replit database python

96 views Asked by At

In the python code below, I am getting the raw data for the key "users" in my database. However I need the raw data only for the key "shares" inside of "users". How would I do this?

Python code to get "users" data:

db.get_raw("users")

Database:

{
  "users": {
    "[email protected]": {
      "password": 12345,
      "shares": {
        "AAPL": {
          "total_shares": 1,
          "total_cost": 134.51,
          "purchases": [
            {
              "shares": 1,
              "price": 134.51
            }
          ],
          "current_price": "134.51",
          "last_updated": 1671406955.5399585,
          "current_value": 134.51
        }
      }
    }
  }
}

I tried to do:

db["users"]["[email protected]"].get_raw("shares")
db.get_raw("users")["[email protected]"]["shares"]
1

There are 1 answers

0
Dylan Gow On BEST ANSWER

GOT IT!

json.loads(db.get_raw("users")).get("[email protected]").get("shares")

Python JSON Decoding: https://www.guru99.com/python-json.html