问题
I want to achieve the following JSON transformation using Jolt processor in Nifi
Input JSON
{
"topLevel": {
"secondLevelA": {
"thirdLevelA": [
{
"norsemen": "huntinSouth",
"value": "AAA"
},
{
"norsemen": "huntinNorth",
"value": "BBB"
}
]
},
"secondLevelB": {
"thirdLevelB": [
{
"norsemen": "huntinNorth",
"oddCode": "AAA301"
},
{
"norsemen": "huntinNorth",
"oddCode": "BBB701"
},
{
"norsemen": "huntinWest",
"oddCode": "AAA701"
}
]
}
}
}
Output JSON
{
"NAME": [
{
"norsemen": "huntinSouth",
"value": "AAA",
"refValue": []
},
{
"norsemen": "huntinNorth",
"value": "BBB",
"refValue": [
{
"oddCode": [
"BBB701"
]
}
]
}
]
}
I would like to test for matches between the values of secondLevelA.thirdLevelA.norsemen and secondLevelB.thirdLevelB.norsemen. If one or more matches is found, all values of secondLevelB.thirdLevelB.oddCode contained in the same set as the matching norsemen would be placed in the output in the same set as the corresponding matching norsemen.
Is there a way to do this using existing Jolt Operations?
回答1:
seems you have some non-declarative logic that could not be covered with jolt.
From jolt description:
Jolt :
- focuses on transforming the structure of your JSON data, not manipulating specific values
- The idea being: use Jolt to get most of the structure right, then write code to fix values
The Stock transforms are:
shift : copy data from the input tree and put it the output tree
default : apply default values to the tree
remove : remove data from the tree
sort : sort the Map key values alphabetically ( for debugging and human readability )
cardinality : "fix" the cardinality of input data. Eg, the "urls" element is usually a List, but if there is only one, then it is a String
I don't see here kind of if/then/else
So, I think your task could not be covered with just jolt
for me the easiest way will be script processor with JavaScript or Groovy language.
来源:https://stackoverflow.com/questions/44169511/jolt-transformation-match-values-in-separate-branches-json