Skip to content

Instantly share code, notes, and snippets.

@ConstBur
Created October 3, 2025 18:07
Show Gist options
  • Select an option

  • Save ConstBur/e2a9ef2ff30a9db5da4c92d34c0f68c5 to your computer and use it in GitHub Desktop.

Select an option

Save ConstBur/e2a9ef2ff30a9db5da4c92d34c0f68c5 to your computer and use it in GitHub Desktop.
Jq stuff
#!/bin/bash
jq -s 'add | group_by(.id) | [.[] | reduce . as $item ({ "id": "", "prop1": "", "iface": "" }; { "id": $item.[0].id, "prop1": $item.[0].prop1, "iface": $item.[1].prop2[0].ifa
ce })]' obj1.json obj2.json > output.json
[
{
"id": "id1",
"prop1": "test1",
"to_remove": "remove me"
},
{
"id": "id2",
"prop1": "test2",
"to_remove": "remove me"
},
{
"id": "id3",
"prop1": "test3",
"to_remove": "remove me"
}
]
[
{
"id": "id1",
"prop2": [
{
"iface": "value1"
}
]
},
{
"id": "id2",
"prop2": [
{
"iface": "value2"
}
]
},
{
"id": "id3",
"prop2": [
{
"iface": "value3"
}
]
}
]
[
{
"id": "id1",
"prop1": "test1",
"iface": "value1"
},
{
"id": "id2",
"prop1": "test2",
"iface": "value2"
},
{
"id": "id3",
"prop1": "test3",
"iface": "value3"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment