Within a JSON I have a rope length with a metric value and my task is to generate a “twin” with imperial output. Depending on the unit of measure (uom) specified in the “metric” input, an imperial value should be calculated. The value after ‘unit-‘ in the key is always variable.
This is my input JSON.
{
“unit-1012108-unitNo”: “1012108”,
“unit-1012108-description”: “IGNITE PROTON WIND”,
“unit-1012108-category”: “211”,
“unit-1012108-att-rope_length-identifier”: “rope_length”,
“unit-1012108-att-rope_length-type”: “attribute”,
“unit-1012108-att-rope_length-attributeDataType”: “DECIMAL”,
“unit-1012108-att-rope_length-values-0-value”: “5.21”,
“unit-1012108-att-rope_length-values-0-uom”: “cm”
}
This is my desired Output JSON. The two auxiliary fields ‘-calc-‘ can be removed later.
The task of my Spec should be to calculate the 2.03 inch.
{
“unit-1012108-att-rope_length-identifier” : “rope_length”,
“unit-1012108-att-rope_length-type” : “attribute”,
“unit-1012108-att-rope_length-values-0-uom” : “cm”,
“unit-1012108-att-rope_length-values-0-value” : “5.21”,
“unit-1012108-att-rope_length_imp-identifier” : “rope_length_imp”,
“unit-1012108-att-rope_length_imp-type” : “attribute”,
“unit-1012108-att-rope_length_imp-values_0-uom” : “inch”,
“unit-1012108-att-rope_length_imp-values_0-value” : “2.03”,
“unit-1012108-rope_length-calc_imp” : “0.39”,
“unit-1012108-rope_length_calc_metric” : “5.21”
}
I’m stuck on the spec. My questions are here. How can I multiply ‘unit–rope_length-calc_imp’ and ‘unit–rope_length_calc_metric’ and then assign the value to ‘unit-*-att-rope_length_imp-values_0-value’? This is where I’ve gotten so far:
[
{
“operation”: “shift”,
“spec”: {
“unit--att-rope_length-values-0-value”: [
“&”,
“unit-&(0,1)-att-rope_length_imp-values_0-value”,
“unit-&(0,1)-rope_length_calc_metric”
],
“unit--att-rope_length-values-0-uom”: [
“&”,
“unit-&(0,1)-att-rope_length_imp-values_0-uom”
],
“unit--att-rope_length-identifier”: [
“&”,
“unit-&(0,1)-att-rope_length_imp-identifier”
],
“unit--att-rope_length-type”: [
“&”,
“unit-&(0,1)-att-rope_length_imp-type”
]
}
},
{
“operation”: “modify-overwrite-beta”,
“spec”: {
“unit--att-rope_length_imp-identifier”: “=concat(rope_length,’_imp’)”
}
},
{
“operation”: “shift”,
“spec”: {
“unit--att-rope_length_imp-values_0-uom”: {
“m”: {
“#feet”: “&2”,
“#3.28”: “unit-&(2,1)-rope_length-calc_imp”
},
“cm”: {
“#inch”: “&2”,
“#0.39”: “unit-&(2,1)-rope_length-calc_imp”
},
“mm”: {
“#inch”: “&2”,
“#0.04”: “unit-&(2,1)-rope_length-calc_imp”
},
““: {
“@(2,&1)”: “&2”
}
},
““: “&”
}
},
{
“operation”: “sort”
}
]
Any hint would be highly appreciated.