Используя следующую команду:
jq -s '
def merge:
{"protocol": .[0].protocol,
"port": .[0].port,
"name": .[0].name,
"stubs": (reduce .[].stubs as $item ([]; . + $item) | unique)};
[[.[].imposters[]] | group_by(.port) | .[] | merge] |
{"imposters": .}' a.json
Этот тип вывода может быть сгенерирован:
{
"imposters": [
{
"protocol": "http",
"port": 9000,
"name": "sanc",
"stubs": []
},
{
"protocol": "http",
"port": 9001,
"name": "sanp",
"stubs": [
{
"predicates": [
{
"deepEquals": {
"path": "/pay/5"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA6quBQAAAP//AwBDv6ajAgAAAA=="
}
}
]
},
{
"predicates": [
{
"deepEquals": {
"path": "/pay/resources"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA4yRQYvCMBCF="
}
}
]
},
{
"predicates": [
{
"deepEquals": {
"path": "/user/access/pilot"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA6quBQAAAP//AwBDv6ajAgAAAA=="
}
}
]
},
{
"predicates": [
{
"deepEquals": {
"path": "/user/access/resources"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA4yRQYvCMBCF="
}
}
]
}
]
}
]
}