Hi @vosy,
It is very possible. Please find the steps you should do to achieve the objective.
For example, here is the original JSON:
{
"variants": {
"variant": [
{
"by-lang": {
"data": [
{
"name": "A-board A1 Complete Set Bread English",
"@lang": "eu",
"description": "Complete A-Board with print design ..."
},
{
"name": "A-board A1 Complete Set Bread English",
"@lang": "es"
},
{
"name": "A-board A1 Complete Set Bread English",
"@lang": "cz",
"description": "CZ Complete A-Board with print design ..."
}
]
}
},
{
"by-lang": {
"data": [
{
"head": {
"title": "A-board A1 stojan s tiskem pla ...",
"keywords": "A-board A1 Complete Set Coffee",
"description": "head description"
},
"name": "A-board A1 Complete Set Bread English",
"@lang": "pt"
},
{
"name": "A-board A1 Complete Set Bread English",
"@lang": "cz"
}
]
}
}
]
},
"common-data": {
"by-lang": {
"data": [
{
"@lang": "cz",
"description": ""
},
{
"@lang": "es",
"description": "es default desc"
}
]
}
}
}
First, we should copy the common-data.by-lang.data
array to each variant data using Recursively copy values to children. This will allow each variant data to access common data since a deeper object in an array can’t access values from the higher level directly. The common data will be available as default_lang
.
Then, we should loop through the variant data using Execute entity transformers and Node, transform nodes. This allows us to put transformers that will apply to each object separately in the array.
Inside the Node, transform nodes, put another Recursively copy values to children to copy the @lang
to each lang in the common data array for filtering purposes later. The selected lang will be available as use_lang
on each common lang.
Still inside the same Node, transform nodes, put a Value Setter to set the use_description
property using JMESPath.
&{description || (default_lang[?"@lang" == use_lang].description | [0]) || head.description || 'Description does not exist'}
Finally, you can remove the temporary default_lang
property from each variant data using Key Filter.
Below is the result of the transformations.
{
"variants": {
"variant": [
{
"by-lang": {
"data": [
{
"name": "A-board A1 Complete Set Bread English",
"@lang": "eu",
"description": "Complete A-Board with print design ...",
"use_description": "Complete A-Board with print design ..."
},
{
"name": "A-board A1 Complete Set Bread English",
"@lang": "es",
"use_description": "es default desc"
},
{
"name": "A-board A1 Complete Set Bread English",
"@lang": "cz",
"description": "CZ Complete A-Board with print design ...",
"use_description": "CZ Complete A-Board with print design ..."
}
]
}
},
{
"by-lang": {
"data": [
{
"head": {
"title": "A-board A1 stojan s tiskem pla ...",
"keywords": "A-board A1 Complete Set Coffee",
"description": "head description"
},
"name": "A-board A1 Complete Set Bread English",
"@lang": "pt",
"use_description": "head description"
},
{
"name": "A-board A1 Complete Set Bread English",
"@lang": "cz",
"use_description": "Description does not exist"
}
]
}
}
]
},
"common-data": {
"by-lang": {
"data": [
{
"@lang": "cz",
"description": ""
},
{
"@lang": "es",
"description": "es default desc"
}
]
}
}
}
We hope our explanation is clear to you. Feel free to let us know if you find any issues.