vishwanatha handadi
vishwanatha handadi

Reputation: 37

How to use the Nifi JoltJSONTransform spec?

I wish to use the JoltTransformJSON spec that can be used to convert the input to output.

I have tried to use map to List and other syntax, but was not been successful so far.

Expected input:

{
    "params": "sn=GH6747246T4JLR6AZ&c=QUERY_RECORD&p=test_station_name&p=station_id&p=result&p=mac_addresss"
}

Expected output:

{
    "queryType": "scan",
    "dataSource": "xyz",
    "resultFormat": "list",
    "columns": ["test_station_name", "station_id", "result", "mac_address"],
    "intervals": ["2018-01-01/2018-02-09"],
    "filter": {
        "type": "selector",
        "dimension": "sn",
        "value": "GH6747246T4JLR6AZ"
    }
}

Except for the content inside Columns and dimension and value attributes rest of the fields are hardcoded.

Upvotes: 0

Views: 79

Answers (1)

Andy
Andy

Reputation: 14184

As all of the data is contained in a single JSON key/value, I don't think JoltTransformJSON is the best option here. I actually think writing a simple script in Python/Groovy/Ruby to split the querystring value and write it out as JSON is easier and less complicated to maintain. I would recommend Groovy specifically (you can use the specialized ExecuteGroovyScript processor), as it is the most performant & robust in Apache NiFi and has excellent JSON handling.

Upvotes: 1

Related Questions