i need py file to merge all json in same folder

Viewed 14

I'd like to ask your help to merge all json files in same folder after filtering data in nested dictionary. I wanna have only results of dictionary which is marked as "ID":1 You can see json files and desired "merged.json" in the below.

----------------------json1--------------------------

{
  "results": [
    {
      "Elems": [
        {
          "Elems": [
            {
              "ligName": "Premier League",
              "nameGame": "Chelsea - Liverpool",
              "score": "2-2"
            }
          ]
        }
      ],
      "ID": 1
    },
    {
      "Elems": "bbb",
      "ID": 2,
    },
    {
      "Elems": "ccc",
      "ID": 3,
    },
    {
      "Elems": "ddd",
      "ID": 4,
    }
  ]
}

----------------------json2--------------------------

{
  "results": [
    {
      "Elems": "xxx",
      "ID": 4,
    },
    {
      "Elems": "yyy",
      "ID": 2,
    },
    {
      "Elems": [
        {
          "Elems": [
            {
              "ligName": "Bundesliga",
              "nameGame": "Bayern - Dortmund",
              "score": "3-0"
            }
          ]
        }
      ],
      "ID": 1
    },
    {
      "Elems": "zzz",
      "ID": 3,
    }
  ]
}

merged.json

{
  "results": [
    {
      "Elems": [
        {
          "Elems": [
            {
              "ligName": "Premier League",
              "nameGame": "Chelsea - Liverpool",
              "score": "2-2"
            }
          ]
        },
        {
          "Elems": [
            {
              "ligName": "Bundesliga",
              "nameGame": "Bayern - Dortmund",
              "score": "3-0"
            }
          ]
        }
      ]
    }
  ]
}

THanks for your interest.

0 Answers
Related