title: Combining JSON by common key-value pairs
body: <p>I'm currently working through an issue, and can't seem to figure this one out. Here's some data so you know what I'm talking about below:</p>
  
  <p>foo.json</p>
  
  <pre><code>{
      "Schedule": [
          {
              "deviceId": 123,
              "reservationId": 123456,
              "username": "jdoe"
          },
          {
              "deviceId": 456,
              "reservationId": 589114,
              "username": "jsmith"
          }
      ],
      "serverTime": 1522863125.019958
  }
  </code></pre>
  
  <p>bar.json</p>
  
  <pre><code>[
      {
          "a": {
              "b": "10.0.0.1",
              "c": "hostname1"
          },
          "deviceId": 123
      },
      {
          "a": {
              "b": "10.0.0.2",
              "c": "hostname2"
          },
          "deviceId": 456
      }
  ]
  </code></pre>
  
  <p>foobar.json</p>
  
  <pre><code>{
      "Schedule": [
          {
              "deviceId": 123,
              "reservationId": 123456,
              "username": "jdoe",
              "a": {
                  "b": "10.0.0.1",
                  "c": "hostname1"
              }
          }
          },
          {
              "deviceId": 456,
              "reservationId": 789101,
              "username": "jsmith",
              "a": {
                  "b": "10.0.0.2",
                  "c": "hostname2"
              }
          }
      ],
      "serverTime": 1522863125.019958
  }
  </code></pre>
  
  <p>I'm trying to use jq to do this, and had some help from this post: <a href="https://github.com/stedolan/jq/issues/1090" rel="nofollow noreferrer">https://github.com/stedolan/jq/issues/1090</a>
  The goal is to be able to combine JSON, using some key as a common point between the documents. The data may be nested any amount of levels.. In this case foo.json has nested data only two levels deep, but needs to be combined with data nested 1 level deep.</p>
  
  <p>Any and all suggestions would be super helpful. I'm also happy to clarify and answer questions if needed. Thank you!</p>