Hi,

While I'm writing up to understand how it works, I found simpler Jolt
spec to do the transformation.

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "PersonalDetails": "@(1,ID).PersonalDetails",
        "OfficeDetails": "@(1,ID).OfficeDetails"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "[#2].ID",
        "@.OfficeDetails": "[#2].OfficeDetails",
        "@.PersonalDetails": "[#2].PersonalDetails"
      }
    }
  }
]

Please also look at this blog post for detail.
http://ijokarumawak.github.io/nifi/2016/11/22/nifi-jolt/

Koji

On Mon, Nov 21, 2016 at 10:34 PM, Koji Kawamura <[email protected]> wrote:
> Hi Manojkumar,
>
> Thanks for sharing the sample Json files.
>
> It was not a simple conversion, but I was able to get the expected
> outcome using JoltTransformJson processor.
> Using following 'Chain' specification:
>
> [
>   {
>     "operation": "shift",
>     "spec": {
>       "*": {
>         "PersonalDetails": "PersonalDetailList.@(1,ID)",
>         "OfficeDetails": "OfficeDetailList.@(1,ID)"
>       }
>     }
>   },
>   {
>     "operation": "shift",
>     "spec": {
>       "OfficeDetailList": {
>         "*": {
>           "$": ["Merged[#2].ID", "Merged[#2].PersonalID"],
>           "@": "Merged[#2].OfficeDetails"
>         }
>       },
>       "PersonalDetailList": "PersonalDetailList"
>     }
>   },
>   {
>     "operation": "shift",
>     "spec": {
>       "Merged": {
>         "*": {
>           "ID": "[&1].ID",
>           "OfficeDetails": "[&1].OfficeDetails",
>           "PersonalID": {
>             "*": {
>               "@(4,PersonalDetailList.&)": "[&3].PersonalDetails"
>             }
>           }
>         }
>       }
>     }
>   }
> ]
>
> Above spec applies three 'shift' operations.
> Although it's working, It's hard to explain how it actually works...
> I'm going to write a blog post about details so that I can refer it
> later. I will share when it's ready.
>
> I was referring this 'Join by 2 Shifts' example [1]. It requires one
> more shift to apply this solution.
>
> [1] https://github.com/bazaarvoice/jolt/issues/205
>
> Thanks,
> Koji
>
>
> On Mon, Nov 21, 2016 at 2:50 PM, Manojkumar Ravichandran
> <[email protected]> wrote:
>> Hi koji,
>>
>>
>> I have tried the EvaluateJsonPath processor but can't able to produce the
>> required output,here  the sample Input and required output json file has
>> been attached
>>
>> After that i want implement the same scenario with different json or CSV
>> files, Out thing is to iterate the content of flowfile with each values of
>> the another CSV or Json file.
>>
>>
>> Regards,
>>
>> Manojkumar R
>>
>>
>> On Mon, Nov 21, 2016 at 5:40 AM, Koji Kawamura <[email protected]>
>> wrote:
>>>
>>> Hi Manojkumar,
>>>
>>> To extract elements from a single JSON flow file, then
>>> EvaluateJsonPath or JoltTransformJSON would be able to do the job.
>>> Could you share the entire sample input JSON file (including the
>>> elements you'd like to filter out) ?
>>>
>>> Thanks,
>>> Koji
>>>
>>> On Sat, Nov 19, 2016 at 10:27 PM, Manojkumar Ravichandran
>>> <[email protected]> wrote:
>>> > Hi Team,
>>> >
>>> > Is it possible to filter and eliminate the values in the json data
>>> > format
>>> > using the nifi processors
>>> >
>>> > Note:I have used some processor like extract text,Attribute
>>> > json,EvaluateJsonpath , but I can't able to generate the required output
>>> >
>>> > For Example:
>>> > I getting a separate flow files like this,from the json data fetched
>>> > {
>>> > "YEAR": "2015",
>>> > "Month": [{
>>> > "MONTH": "Jan",
>>> > }]
>>> > }
>>> >
>>> > {
>>> > "YEAR": "2016",
>>> > "Month": [{
>>> > "MONTH": "feb",
>>> > }]
>>> > }
>>> >  the output I need should be in the form of given below,
>>> > {
>>> > "Year": 2016,
>>> > "Months": [{
>>> > "Month": "Jan",
>>> > },
>>> > {
>>> > "Month": "Feb",
>>> > }]
>>> > }
>>> >
>>> >
>>> > Regards,
>>> > Manojkumar R
>>
>>

Reply via email to