On Sun, 3 Apr 2022 at 16:59, Kirill Ratkin via Python-list <python-list@python.org> wrote: > > Hi Marco. > > Recently I met same issue. A service I intergated with was documented > badly and sent ... unpredictable jsons. > > And pattern matching helped me in first solution. (later I switched to > Pydantic models) > > For your example I'd make match rule for key path you need. For example: > > > data = {"users": [{"address": {"street": "Baker"}}]} > > match data: > case {"users": [{"address": {"street": street}}]}: > print(f"street: {street}") > > case _: > print("unsupported message structure")
Hi. I think your solution is very brilliant, but I'm a bit allergic to pattern matching... :D Maybe it's me, but I found it really strange and "magical". -- https://mail.python.org/mailman/listinfo/python-list