Jq: How to move the child members to parent?
问题 Consider the following json: { a: { b: { c: 1, d: 2 } } } How can I move all the properties of b to be under the parent a: { a: { c: 1, d: 2, b: {} } } 回答1: For this particular case, you could do this: $ jq '.a |= (.b = {}) + .b' input.json Here we're updating object a with the original contents with b replaced with an empty object and combining it with the contents of the original b . If that was too hard to reason about, this might be easier to follow: $ jq '.a |= with_entries(if .key == "b