jsonapache-nifikylo

Split JSON into two individual JSON objects using Nifi


I have a JSON like

{
    "campaign_key": 316,
    "client_key": 127,
    "cpn_mid_counter": "24",
    "cpn_name": "Bopal",
    "cpn_status": "Active",
    "clt_name": "Bopal Ventures",
    "clt_status": "Active"
}

Expected output

1st JSON :

{
    "campaign_key": 316,
    "client_key": 127,
    "cpn_mid_counter": "24",
    "cpn_name": "Bopal",
    "cpn_status": "Active"
}

2nd JSON:

{
    "clt_name": "Bopal Ventures",
    "clt_status": "Active"
}

How do I acheive this by using NIFI? Thanks.


Solution

  • Karthik,

    Use EvaluateJsonPath processor to get those all json Values by using its keys.

    Example: $.campaign_key for gets compaign key value and $.clt_name for get clt name.

    Like above one you can get all jsons.

    Then use ReplaceText Processor for convert single json into two jsons.

    {"Compaign_Key":${CompaignKey},...etc}
    {"Clt_name":${clt_name}}
    

    It will convert single json into two jsons.

    Hope this helpful and let me know if you have issues.