Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Nifi 1.7.1 Flatten Json with delimiter

I am using the Flatten Json processor with delimiter _ , this works fine in so far that it does flatten nested records. But I also noticed that it interferes with keys which already have "_" in them. For eg:

{
"first_name": "myfirstname",
"last_name":  "mylastname",
"address": {
            "billing": "mybilling",
            "shipping": "myshipping"
           }
}

flattened to:

{
"[\"first_name\"]": "myfirstname",
"[\"last_name\"]":  "mylastname",
"address_billing": "mybilling",
"address_shipping": "myshipping"
 }

while, 'address' record is flattened as expected, the keys first_name and last_name which have an _ character are also disturbed. Is there a way I can circumvent this? (perhaps a way to escape non record types?)

like image 787
irrelevantUser Avatar asked Nov 01 '25 17:11

irrelevantUser


1 Answers

To workaround this issue you can use either

  • JoltTransformJson processor

    (or)

  • Keep the seperator(like '|','-'..etc) in FlattenJson which is not present in key names.

1. Using JoltTransformJson Processor:

Spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "address": {
        "*": "address_&"
      }
    }
  }
]

Output:

{
  "first_name" : "myfirstname",
  "last_name" : "mylastname",
  "address_billing" : "mybilling",
  "address_shipping" : "myshipping"
}

2.FlattenJson Processor:

enter image description here

Output:

{
    "first_name": "myfirstname",
    "last_name": "mylastname",
    "address|billing": "mybilling",
    "address|shipping": "myshipping"
}
like image 94
notNull Avatar answered Nov 04 '25 14:11

notNull



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!