-1

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": {
    "dylan@dylan.com": {
      "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"]["dylan@dylan.com"].get_raw("shares")
db.get_raw("users")["dylan@dylan.com"]["shares"]
Dylan Gow
  • 11
  • 3

1 Answers1

1

GOT IT!

json.loads(db.get_raw("users")).get("dylan@dylan.com").get("shares")

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

Dylan Gow
  • 11
  • 3