s1s1ty / py-jsonq

A simple Python package to Query over Json Data
MIT License
124 stars 22 forks source link

How to access nested dictionaries? #8

Open aiqc opened 2 years ago

aiqc commented 2 years ago

I have a file of records structured like so:

[
    {
        "case_id": 1,
        "demographic": {
            "race": "white",
            "age": 55,
        }
    },
    {
        "case_id": 2,
        "demographic": {
            "race": "white",
            "age": 65,
        }
    },
    {
        "case_id": 3,
        "demographic": {
            "race": "black",
            "age": 57,
        }
    }
]

I can access case id fine

q.where('case_id', '=', 1).get()

But I can't seem to use at to drill into the demographic key

q.at('demographic')

"KeyError: 'Key not exists'"
aiqc commented 2 years ago

Related/duplicate: https://github.com/s1s1ty/py-jsonq/issues/2

aiqc commented 2 years ago

This works:

q.at('0.demographic').get()

But I can't figure out how to make it do at('all.demographic')

wesley-staples commented 3 months ago

I have just run into this same issue. Has anyone found a workaround yet? @s1s1ty if you have some time could you look into this?