EDIT: To answer correctly I will consider your JSON in the post as good, so here is my answer:
@.{image1: @[0].image1, image2: @[1].image2, image3: @[1].image3} | [@.image1, @.image2, @.image3] | @.[{image1: @[0]},{image2: @[1]},{image3: @[2]}]
with this
you get this:
[
{
"image1":{
"registry_url":"blah"
}
},
{
"image2":{
"registry_url":"blah"
}
},
{
"image3":{
"registry_url":"blah"
}
}
]
And with this request:
@[*].{name: keys(@)[0], registry_url: join('',*.registry_url)}
you will have this result:
[
{
"name": "image1",
"registry_url": "blah"
},
{
"name": "image2",
"registry_url": "blah"
},
{
"name": "image3",
"registry_url": "blah"
}
]
If there is any problem with registry_url(with the type) you od not have to use join
function you can use max
or min
function, just I was need a function to convert an array to a value :) !
If you want to flatten the result again (withouth square bracket) you normally can't do it in an easy way(I don't think it's possible, but if it's possible it would be a little bit tricky).
so the entire request is: @.{image1: @[0].image1, image2: @[1].image2, image3: @[1].image3} | [@.image1, @.image2, @.image3] | @.[{image1: @[0]},{image2: @[1]},{image3: @[2]}] | @[*].{name: keys(@)[0], registry_url: join('',*.registry_url)}
It's work in fact, but I don't think it's the best way !
And if you want without square bracket(only curly bracket) do this(but if we do this we have to put attribute on the object:
so here is the request: @.{image1: @[0].image1, image2: @[1].image2, image3: @[1].image3} | [@.image1, @.image2, @.image3] | @.[{image1: @[0]},{image2: @[1]},{image3: @[2]}] | @[*].{name: keys(@)[0], registry_url: join('',*.registry_url)} | @.{obj1: @[0], obj2: @[1], obj3: @[2]}}
Here's the result:
{
"obj1": {
"name": "image1",
"registry_url": "blah"
},
"obj2": {
"name": "image2",
"registry_url": "blah"
},
"obj3": {
"name": "image3",
"registry_url": "blah"
}
}