Created 03-13-2018 12:17 PM
Hi,
I have a requirement for transforming JSON on Nifi which seems simple but I haven't been able to solve:
Input json:
{
"agent-submit-time" : -1,
"agent-end-time" : 123445,
"agent-name" : "Marie Bayer-Smith"
}Desired:
{
"agent_submit_time" : -1,
"agent_end_time" : 123445,
"agent_name" : "Marie Bayer-Smith"
}-I don't want to use the ReplaceText processor since replacing "-" for "_" might impact values too
-I need this to be able to infer AVRO schema on incoming JSON records (AVRO does not like the dashes at all)
-since I already use a Jolt processor for another transformation in the JSON it makes sense to include it in the same processor to prevent unnecessary Nifi overhead.
I think I would need the JoltTransformJSON processor as it is very powerful (but the syntax evades me) for this but open for other options too.
Created 03-13-2018 05:12 PM
You can use the following JOLT spec in the JoltTransformJSON processor:
[
{
"operation": "shift",
"spec": {
"*-*-*": "&(0,1)_&(0,2)_&(0,3)",
"*-*": "&(0,1)_&(0,2)",
"*": "&"
}
}
]Note that you have to add an entry for each "level" of name matching, so if you could have elements with 4 dashes, you'd need an extra line at the top, following the same pattern.
Created 08-15-2018 06:33 PM
Thanks @Matt Burgess
I will try it and let you know if it gives problems.