1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to handle missing keys in list of JSON objects in Python

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list of dicts that are JSON objects, like this:

    [{'addressId': 12345, 'city': 'London', 'country': 'UK'}, {'addressId': 67890, 'city': 'Berlin'}


    For some of the entries there are some JSON keys missing (not just the values) - in the example above the second address is missing the country. This causes problems down the line when I want to write this data to MySQL.

    So I think what I want to do is add the missing keys with empty values. I'm wondering (a) if this is the right approach, and (b) how I would go about doing that.

    FWIW, we're talking about a few million rows.

    Any hints are greatly appreciated.

    Continue reading...

Compartilhe esta Página