Support Questions
Find answers, ask questions, and share your expertise

I have a nested JSON data which I am reading through KAFKA to writing to Elastic using nifi. Before writing to elastic I want to flatten the file, i.e shift the JSON content present in the nest to the main json content

New Contributor

I have a nested JSON data which I am reading through KAFKA to writing to Elastic using nifi. Before writing to elastic I want to flatten the file, i.e shift the JSON content present in the nest to the main json content

JSON INPUT

{ "Rating": 1, "SecondaryRatings": { "Design": 4, "Price": 2, "RatingDimension3": 1 } }

JSON OUTPUT

{ "rating-primary" : 1, "rating-Design" : 4, "rating-Price" : 2, "rating-RatingDimension3" : 1 }

I understand that in nifi JOLTTransformJSON can be used here but could not find any detailed tutorials . can someone explain in detail by taking a use case ?

1 REPLY 1

Super Guru

@Ishant Kathuria

For your expected output Jolt Spec would be

[
  {
    "operation": "shift",
    "spec": {
      "Rating": "rating-primary", //change Rating name to rating-primary
      "SecondaryRatings": { //append rating- for all SecondaryRatings list
        "*": "rating-&"
      }
    }
  }
]

Input:-

{
  "Rating": 1,
  "SecondaryRatings": {
    "Design": 4,
    "Price": 2,
    "RatingDimension3": 1
  }
}

Output:-

{
  "rating-primary" : 1,
  "rating-Design" : 4,
  "rating-Price" : 2,
  "rating-RatingDimension3" : 1
}

Jolt Configs:-

47455-jolt.png

Jolt Spec Validation:-

If you want to test your jolt spec

Right Click on JOLTTransformJSON processor and click on Advanced left down corner. you can specify your SPEC, input and we can validate the spec.

47454-jolt.png

(or)

Click on this link.

Please refer to below community Questions/Articles for tutorials.

https://community.hortonworks.com/questions/137782/nifi-explode-a-json-array-while-keeping-root-leve...

https://community.hortonworks.com/questions/147362/jolttransformjson-spec.html

https://community.hortonworks.com/questions/152046/nifi-how-to-use-jolt-to-add-json-keyvalue-dynamic...

https://community.hortonworks.com/articles/105965/expression-language-with-jolt-in-apache-nifi.html

https://community.hortonworks.com/articles/44726/json-to-json-simplified-with-apache-nifi-and-jolt.h...

http://ijokarumawak.github.io/nifi/2016/11/22/nifi-jolt/

.

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.


jolt.png