{
"test_logoCollection": {
"items": [
{
"globalRef": {
"id": "Header",
"key": "Btl6om8lm9ojt0M0jcbRW"
},
"showBorder": false,
"components": {
"items": []
},
"image": {
"url": "https://greatwall-sandbox-sandbox-image.imgix.net/1386588286/xpm/logo.png?auto=compress",
"altText": null
}
}
]
}
}{
"results": {
"ops": [
{ "path": "items[0]", "mapping": "$finalResolver[0].params.logo[0]" },
{ "path": "items[1]", "mapping": "$finalResolver[1].params.logo[0]" },
{ "path": "items[0].globalRef", "mapping": "$finalResolver[0]" },
{ "path": "items[1].globalRef", "mapping": "$finalResolver[1]" }
]
}
}-
We set
itemsto the results of the JSONPath / mapping statement. Assuming everyitemin the$finalResolverarray has alogo[0]then this will be the same length as the$finalResolverarray, and items will have hoisted thelogo[0]object up to the top. -
We iterate this new
itemsarray, which should be the same length as the$finalResolverarray. Using an expression, we are able toget(lodash.fp.get) the full value of the$finalResolverroot object, and set it under theglobalRefproperty. Note that you will have duplicated data in your return objects, since$finalResolveris necessarily inclusive of.params.logo[0]. That said, you could remove that duplicated data using theopremovein a later step in theops.
{
"results": {
"ops": [
{
"path": "items",
"mapping": "$finalResolver[*].params.logo[0]"
},
{
"path": "items[*].globalRef",
"mapping": [
["expressionEval", { "expression": "get($loop.key, $finalResolver)" }]
]
}
]
}
}{
"results": {
"ops": [
{
"path": "items",
"mapping": "$finalResolver[*]"
},
{
"path": "items[*]",
"mapping": "$finalResolver[*].params.logo[0]"
},
{
"path": "items[*].globalRef",
"mapping": "$loop.item"
},
{
"path": "items[*].id",
"op": "remove"
},
{
"path": "items[*].key",
"op": "remove"
},
{
"path": "items[*].params",
"op": "remove"
}
]
}
}
Thank you so much for your time and efforts! What you wrote describes precisely the issue I'm having and the solution I want to reach. The approach is indeed easy to understand and seems logical but it returned three null objects:
The query:
But it only needed a simple change to return the results:
However, globalRef mapping doesn't seem to work. I have tried to use the source $finalResolver instead of $loop.item but the result were still null. Just when I use a specific index it returns the globalRef of that element value, or when I use the previous mapping approach for globalRef (but it returns the elements in order, not the correct reference)