Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

JoltTransformJSON - transform json array without a parent tag and send the data to a Camel Context

JoltTransformJSON - transform json array without a parent tag and send the data to a Camel Context

New Contributor

I need to transform a JSON data using theJoltTransformJSONinside Nifi, here's my spec which I am using for the transformation:

<code>[{
"operation": "shift",
"spec": {
    "*": {
        "Header": {
            "readOn": "created_date_time",
            "fileName": "readFile"
        },
        "Data": {
            "id": "Id",
            "first_name": "First_Name",
            "last_name": "Last_Name",
        }
    }
}}]

My input data:

<code>[{
"Header": {
    "readOn": "2017/04/18 10:55:05",
    "fileName": "sample1.csv",
    "recordNum": 1
},
"Data": {
    "last_name": "Martin",
    "id": 21,
    "first_name": "Clarence"
}
}, {
"Header": {
    "readOn": "2017/04/18 10:55:05",
    "fileName": "sample.csv",
    "recordNum": 2
},
"Data": {
    "last_name": "Graham",
    "id": 22,
    "first_name": "Walter"
}
}]

Output what I m getting:

<code>{
"created_date_time": ["2017/04/18 10:55:05", "2017/04/18 10:55:05"],
"readFile": ["sample1.csv", "sample2.csv"],
"Id": [21, 22],
"First_Name": ["Clarence", "Walter"],
"Last_Name": ["Martin", "Graham"]
}

The required output:

<code>[{
"recordNum": 1,
"Header": {
    "created_date_time": "2017/04/18 10:55:05",
    "readFile": "getusroi.csv"
},
"Data": {
    "Last_Name": "Martin",
    "Id": 21,
    "First_Name": "Clarence"
}
}, {
"recordNum": 2,
"Header": {
    "created_date_time": "2017/04/18 10:55:05",
    "readFile": "getusroi.csv"
},
"Data": {
    "Last_Name": "Graham",
    "Id": 22,
    "First_Name": "Walter"
}
}]

Question:

1) Can someone guide me where all I need to change my jolt spec to achieve the desired transformed output.

2) Need to send this transformed data to a camel route, read blogs on the integration of camel and nifi but didn't find any processor related to that in the latest version(1.1.2), looked at the SpringContextProcessor for the solution but couldn't configure as was unable to find a working example or explanation on it. Can some one guide me to how can it communicate to my camel context and send the required data directly from Nifi.

This is my first time asking a question on here, if I missed any info which I should have provided please do comment.

Don't have an account?
Coming from Hortonworks? Activate your account here