I am trying to adapt the following JSON with jolt
[
{
"id": "abc",
"colour": "black | orange | anthracite",
"material": "polyester | aluminium | v2a | steel",
"temp min": "45 °C",
"temp max": "-35 °C",
"category": "rope",
"length": "18 m"
},
{
"id": "def",
"colour": "black | orange | anthracite",
"material": "polyester | aluminium | v2a | steel",
"temp min": "45 °C",
"temp max": "-35 °C",
"category": "various"
},
{
"id": "ghi",
"colour": "black | orange | anthracite",
"material": "polyester | aluminium | v2a | steel",
"temp min": "45 °C",
"temp max": "-35 °C",
"categorie": "rope",
"length": "10 m"
}
]
The JSON needs to be transformed as follows.
The featureName has to be added as attribute,
as well as the featureUnit (if Unit is available).
That means every time the featureValue ends on
a certain list of specified units "°C, m, cm, mm, Years"
a Unit attribute has to be created and the unit has to be removed from the original value
[
{
"id": "abc",
"featureName_colour": "colour",
"featureValue_colour": "black | orange | anthracite",
"featureName_material": "material",
"featureValue_material": "polyester | aluminium | v2a | steel",
"featureName_temp min": "temp min",
"featureValue_temp min": "45",
"featureUnit_temp min": "°C",
"featureName_temp max": "temp max",
"featureValue_temp max": "-35",
"featureUnit_temp max": "°C",
"featureName_category": "category",
"featureValue_category": "rope",
"featureName_length": "length",
"featureValue_length": "18",
"featureUnit_length": "m"
},
{
"id": "def",
"featureName_colour": "colour",
"featureValue_colour": "black | orange | anthracite",
"featureName_material": "material",
"featureValue_material": "polyester | aluminium | v2a | steel",
"featureValue_temp min": "45",
"featureUnit_temp min": "°C",
"featureName_temp max": "temp max",
"featureValue_temp max": "-35",
"featureUnit_temp max": "°C",
"featureName_category": "category",
"featureValue_category": "various"
},
{
"id": "ghi",
"featureName_colour": "colour",
"featureValue_colour": "black | orange | anthracite",
"featureName_material": "material",
"featureValue_material": "polyester | aluminium | v2a | steel",
"featureValue_temp min": "45",
"featureUnit_temp min": "°C",
"featureName_temp max": "temp max",
"featureValue_temp max": "-35",
"featureUnit_temp max": "°C",
"featureName_categorie": "categorie",
"featureValue_categorie": "rope",
"featureName_length": "length",
"featureValue_length": "10",
"featureUnit_length": "m"
}
]
I managed to solve the featureName Problem with the following spec:
[
{
"operation": "shift",
"spec": {
"*": {
"id": "[&1].&",
"*": {
"$": "[&2].featureName_&",
"@": "[&2].featureValue_&"
}
}
}
}
]
But I have no idea how to solve the featureUnit-Problem.
2
Answers
In addition to the help provided by Barbaros, this spec does the job as well. It is alittle bit clumsy, I know :)
Assuming the whole value patterns are the same as with the presented input, then consider the following spec to distinguish the value sets :