I have the following json record that has 2 arrays that I would like to be combined into one array:
{
"id": "1234X",
"rating": "B",
"files": [
{
"sequenceId": 7,
"show": "No",
"hash": "ABC123",
"collectTime": 1716308631000
},
{
"sequenceId": 13,
"collectTime": 1716308631000
},
{
"sequenceId": 10,
"hash": "DEF234",
"collectTime": 1716308631000
},
{
"sequenceId": 8,
"show": "No",
"collectTime": 1716308631000
}
],
"tags": [
{
"hash": "DEF234",
"tag": "Corrupt"
}
]
}
And the result would be:
{
"id" : "1234X",
"rating" : "B",
"tempFiles" : [ {
"sequenceId" : 7,
"show" : "No",
"hash" : "ABC123",
"collectTime" : 1716308631000
}, {
"sequenceId" : 13,
"collectTime" : 1716308631000
}, {
"sequenceId" : 10,
"hash" : "DEF234",
"tag" : "Corrupt",
"collectTime" : 1716308631000
}, {
"sequenceId" : 8,
"show" : "No",
"collectTime" : 1716308631000
} ]
}
I combined the two arrays into one and set the cardinality to ONE, but I’m confused on how to set the cardinality on array elements that don’t necessarily have the same LHV for every element
I’ve tried the following shift and cardinality operations:
[
{
"operation": "shift",
"spec": {
"files|tags": {
"*": "tempFiles[]"
},
"*": "&"
}
}, {
"operation": "cardinality",
"spec": {
"tempFiles[]": {
"*": {
"hash": "ONE"
}
}
}
}
]
But I get:
{
"id" : "1234X",
"rating" : "B",
"tempFiles" : [ {
"sequenceId" : 7,
"show" : "No",
"hash" : "ABC123",
"collectTime" : 1716308631000
}, {
"sequenceId" : 13,
"collectTime" : 1716308631000
}, {
"sequenceId" : 10,
"hash" : "DEF234",
"collectTime" : 1716308631000
}, {
"sequenceId" : 8,
"show" : "No",
"collectTime" : 1716308631000
}, {
"hash" : "DEF234",
"tag" : "Corrupt"
} ]
}
How do I get one array record that contains the hash and has the collectTime and the tag with the sequenceId? I’m guessing there’s a better way of doing this, but am new with these transforms
voodoo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.