2
I have the following Json to be treated in python:
{
   "lojas": {
      "todas":[
         {
            "CodigoLoja": "001",
            "produtos":[
               {
                  "CodigoProduto": "001AAAAAAA",
                  "dataFabricacao": "11/11/2019",
                  "preco": "300,00"
               },
               {
                  "CodigoProduto": "001BBBBBBB",
                  "dataFabricacao": "2020-11-11",
                  "preco": "400,00"
               }
            ]
         },
         {
            "codigoLoja": "002",
            "produtos":[
               {
                  "CodigoProduto": "002AAAAAAA",
                  "dataFabricacao": "11/11/2018",
                  "preco": "500,00"
               },
               {
                  "CodigoProduto": "002BBBBBBB",
                  "dataFabricacao": "2017-11-11",
                  "preco": "600,00"
               }
            ]
         }
      ]
   }
}
The formatted output I seek is:
codigoLoja      codigoProduto dataFabricacao      preco
001             001AAAAAAA    2019-11-11          300,00
001             001BBBBBBB    2020-11-11          400,00
002             002AAAAAAA    2018-11-11          500,00
002             002BBBBBBB    2017-11-11          600,00
       
I’m doing it this way:
for each in data['lojas']['todas']:
    for produtos in each['produtos']:
        print(each['codigoLoja']+produtos['codigoProduto']+produtos['dataFabricacao']+produtos['preco']) 
This even works, but I wonder if there is a better way to implement, without having to define the name of the fields, because if you include a new field in products (for example, "product description"), do not have to keep changing the code.
Try a pandas implementation. The solution will be simpler and possibly you will be able to automate for any key names entry.
– Lucas