dotty_dict icon indicating copy to clipboard operation
dotty_dict copied to clipboard

No values returned when one item is missing using slices to get a subset of the data

Open girardinsamuel opened this issue 2 years ago • 0 comments

When using slices without missing data it works perfectly:

data = dotty(
    {
        "users": [
            {"first_name": "Sam", "last_name": "Gamji"},
            {"first_name": "John", "last_name": "Doe"},
            {"first_name": ""}
         ]
    }
)

data.get("users.*.first_name") #== ["Sam", "John", ""]

But with one missing item in the subset it returns just None:

data = dotty(
    {
        "users": [
            {"first_name": "Sam", "last_name": "Gamji"},
            {"last_name": "Doe"},
            {"first_name": ""}
         ]
    }
)

data.get("users.*.first_name") #== None

I would expect to get:

data.get("users.*.first_name") #== ["Sam", None, ""]

Is it wanted ? Is it a bug ?

It would be really nice to have this behaviour ! Thanks 🙏 .

girardinsamuel avatar Nov 01 '22 18:11 girardinsamuel