title: Using JQ to replace a value with another value from the same dictionary
body: <p>Given the following JSON file foo.js (stripped down for clarity):</p>
  
  <pre><code>{"a":{"b":[{"x":{"x1":1},"y":{"y1":5}},{"x":{"x1":1},"y":{"y1":6}}]}}
  </code></pre>
  
  <p>I want to replace the value of x1 with the corresponding value of y1. That is, I want to end up with:</p>
  
  <pre><code>{"a":{"b":[{"x":{"x1":5},"y":{"y1":5}},{"x":{"x1":6},"y":{"y1":6}}]}}
  </code></pre>
  
  <p>This replaces the values, but returns only the modified dictionaries rather than the complete JSON file:</p>
  
  <pre><code>% jq -Mc '.a.b[] | .x.x1 = .y.y1' foo.js
  {"x":{"x1":5},"y":{"y1":5}}
  {"x":{"x1":6},"y":{"y1":6}}
  </code></pre>
  
  <p>This works to replace x1 with a constant value:</p>
  
  <pre><code>% jq -Mc '(.a.b[] | .x.x1) |= 9' foo.js
  {"a":{"b":[{"x":{"x1":9},"y":{"y1":5}},{"x":{"x1":9},"y":{"y1":6}}]}}
  </code></pre>
  
  <p>But this attempt to use the same idea doesn't work:</p>
  
  <pre><code>% jq -Mc '(.a.b[] | .x.x1) |= .y.y1' foo.js
  jq: error (at foo.js:1): Cannot index number with string "y"
  </code></pre>