title: Merge JSON Data by Key
body: <p>I am trying to merge several JSON files I have on weather data and am trying to figure out the best way to do it. I've found several other posts that just concatenate the JSON objects or that have the second one overwrite the first in case of the same key, etc but nothing that merges them by key. </p>
  
  <p>Below is a sample of what I'm working with and the output I'd like. Any suggestions on this would be great!</p>
  
  <p>Sample JSON0.json</p>
  
  <pre><code>    {
      "1948": [
          {
              "Seattle": {
                  "city": "Seattle",
                  "data": {
                      "avg_dew_point": "34",
                      "avg_gust_wind": "",
                      "avg_max_temp": "45",
                      "avg_min_temp": "35",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.22",
                      "avg_temp": "40",
                      "avg_wind": "8"
                  },
                  "month": "1",
                  "state": "WA"
              }
          },
          {
              "Chicago": {
                  "city": "Chicago",
                  "data": {
                      "avg_dew_point": "10",
                      "avg_gust_wind": "",
                      "avg_max_temp": "25",
                      "avg_min_temp": "11",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.17",
                      "avg_temp": "18",
                      "avg_wind": "12"
                  },
                  "month": "1",
                  "state": "IL"
              }
          }
      ],
      "1949": [
          {
              "Houston": {
                  "city": "Houston",
                  "data": {
                      "avg_dew_point": "45",
                      "avg_gust_wind": "",
                      "avg_max_temp": "61",
                      "avg_min_temp": "44",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.15",
                      "avg_temp": "53",
                      "avg_wind": "12"
                  },
                  "month": "1",
                  "state": "TX"
              }
          },
          {
              "Seattle": {
                  "city": "Seattle",
                  "data": {
                      "avg_dew_point": "25",
                      "avg_gust_wind": "",
                      "avg_max_temp": "38",
                      "avg_min_temp": "25",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.32",
                      "avg_temp": "31",
                      "avg_wind": "7"
                  },
                  "month": "1",
                  "state": "WA"
              }
          }
      ]
  }
  </code></pre>
  
  <p>Sample JSON1.json</p>
  
  <pre><code>{
      "1948": [
          {
              "Jacksonville": {
                  "city": "Jacksonville",
                  "data": {
                      "avg_dew_point": "45",
                      "avg_gust_wind": "",
                      "avg_max_temp": "61",
                      "avg_min_temp": "44",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.13",
                      "avg_temp": "53",
                      "avg_wind": "8"
                  },
                  "month": "1",
                  "state": "FL"
              }
          },
          {
              "Indianapolis": {
                  "city": "Indianapolis",
                  "data": {
                      "avg_dew_point": "13",
                      "avg_gust_wind": "",
                      "avg_max_temp": "34",
                      "avg_min_temp": "13",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.17",
                      "avg_temp": "24",
                      "avg_wind": "12"
                  },
                  "month": "1",
                  "state": "IN"
              }
          }
      ],
      "1949": [
          {
              "San Jose": {
                  "city": "San Jose",
                  "data": {
                      "avg_dew_point": "",
                      "avg_gust_wind": "",
                      "avg_max_temp": "52",
                      "avg_min_temp": "33",
                      "avg_precipitation": "0.02",
                      "avg_sea_level_pressure": "",
                      "avg_temp": "43",
                      "avg_wind": ""
                  },
                  "month": "1",
                  "state": "CA"
              }
          },
          {
              "Jacksonville": {
                  "city": "Jacksonville",
                  "data": {
                      "avg_dew_point": "55",
                      "avg_gust_wind": "",
                      "avg_max_temp": "73",
                      "avg_min_temp": "54",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.21",
                      "avg_temp": "63",
                      "avg_wind": "5"
                  },
                  "month": "1",
                  "state": "FL"
              }
          }
      ]
  }
  </code></pre>
  
  <p>Sample combinedJSON.json</p>
  
  <pre><code>{
      "1948": [
          {
              "Seattle": {
                  "city": "Seattle",
                  "data": {
                      "avg_dew_point": "34",
                      "avg_gust_wind": "",
                      "avg_max_temp": "45",
                      "avg_min_temp": "35",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.22",
                      "avg_temp": "40",
                      "avg_wind": "8"
                  },
                  "month": "1",
                  "state": "WA"
              }
          },
          {
              "Chicago": {
                  "city": "Chicago",
                  "data": {
                      "avg_dew_point": "10",
                      "avg_gust_wind": "",
                      "avg_max_temp": "25",
                      "avg_min_temp": "11",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.17",
                      "avg_temp": "18",
                      "avg_wind": "12"
                  },
                  "month": "1",
                  "state": "IL"
              }
          },
          {
              "Jacksonville": {
                  "city": "Jacksonville",
                  "data": {
                      "avg_dew_point": "45",
                      "avg_gust_wind": "",
                      "avg_max_temp": "61",
                      "avg_min_temp": "44",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.13",
                      "avg_temp": "53",
                      "avg_wind": "8"
                  },
                  "month": "1",
                  "state": "FL"
              }
          },
          {
              "Indianapolis": {
                  "city": "Indianapolis",
                  "data": {
                      "avg_dew_point": "13",
                      "avg_gust_wind": "",
                      "avg_max_temp": "34",
                      "avg_min_temp": "13",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.17",
                      "avg_temp": "24",
                      "avg_wind": "12"
                  },
                  "month": "1",
                  "state": "IN"
              }
          }
      ],
      "1949": [
          {
              "Houston": {
                  "city": "Houston",
                  "data": {
                      "avg_dew_point": "45",
                      "avg_gust_wind": "",
                      "avg_max_temp": "61",
                      "avg_min_temp": "44",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.15",
                      "avg_temp": "53",
                      "avg_wind": "12"
                  },
                  "month": "1",
                  "state": "TX"
              }
          },
          {
              "Seattle": {
                  "city": "Seattle",
                  "data": {
                      "avg_dew_point": "25",
                      "avg_gust_wind": "",
                      "avg_max_temp": "38",
                      "avg_min_temp": "25",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.32",
                      "avg_temp": "31",
                      "avg_wind": "7"
                  },
                  "month": "1",
                  "state": "WA"
              }
          },
          {
              "San Jose": {
                  "city": "San Jose",
                  "data": {
                      "avg_dew_point": "",
                      "avg_gust_wind": "",
                      "avg_max_temp": "52",
                      "avg_min_temp": "33",
                      "avg_precipitation": "0.02",
                      "avg_sea_level_pressure": "",
                      "avg_temp": "43",
                      "avg_wind": ""
                  },
                  "month": "1",
                  "state": "CA"
              }
          },
          {
              "Jacksonville": {
                  "city": "Jacksonville",
                  "data": {
                      "avg_dew_point": "55",
                      "avg_gust_wind": "",
                      "avg_max_temp": "73",
                      "avg_min_temp": "54",
                      "avg_precipitation": "0.00",
                      "avg_sea_level_pressure": "30.21",
                      "avg_temp": "63",
                      "avg_wind": "5"
                  },
                  "month": "1",
                  "state": "FL"
              }
          }
      ]
  }
  </code></pre>