-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": {
    "[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 Answer 1

1

GOT IT!

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.