Created 11-01-2023 04:33 PM
Need help to convert a date from below JSON file from mm/yy to yyyy-mm format using NIFI
Created 11-02-2023 02:01 AM
@user001,
How I would do this:
- Create an UpdateRecord Processor, where I define a JsonTreeReader, for reading the input file and a JsonRecordSetWriter, for writing the newly formatted file.
- Within this same processor, I would add a new property where I define the path to the column you are trying to modify. In your case, assuming that this is the entire JSON File, you would have /Key/value[*]/Date.
- The value for this newly generated property should be the transformation you are trying to achieve. In your case, it would be ${field.value:toDate("MM/yy"):format("yyyy-MM")}
- Next, within the same exact processor, I would modify the Replacement Value Strategy from the default value into Literal Value.
And that's pretty much all you have to do.
Created 11-01-2023 05:53 PM
@user001 Welcome to the Cloudera Community!
To help you get the best possible solution, I have tagged our NiFi experts @MattWho @cotopaul who may be able to assist you further.
Please keep us updated on your post, and we hope you find a satisfactory solution to your query.
Regards,
Diana Torres,Created 11-02-2023 02:01 AM
@user001,
How I would do this:
- Create an UpdateRecord Processor, where I define a JsonTreeReader, for reading the input file and a JsonRecordSetWriter, for writing the newly formatted file.
- Within this same processor, I would add a new property where I define the path to the column you are trying to modify. In your case, assuming that this is the entire JSON File, you would have /Key/value[*]/Date.
- The value for this newly generated property should be the transformation you are trying to achieve. In your case, it would be ${field.value:toDate("MM/yy"):format("yyyy-MM")}
- Next, within the same exact processor, I would modify the Replacement Value Strategy from the default value into Literal Value.
And that's pretty much all you have to do.
Created 11-03-2023 11:56 AM
Hello , Thankyou for your reply.
In my local NIFI when I created the updateRecord processor, it suppported- UpdateRecord 1.21.0
with which I was able to transform successfully.
But In the Sandbox environment When I created the updateRecord processor, it supported- UpdateRecord 1.18.0.2.1.5.1005-1
with which I am getting below error.
UpdateRecord[id=bbde4766-0009-18f4-0000-00000eaf934b] Failed to process FlowFile[filename=32534d2a-ebfb-4e98-84a8-fdf5c865989f]; will route to failure: java.lang.IllegalStateException: Null String illegal for SerializedString
I have verified the Input Json in both local as well as the Sandbox and are same
But getting the above error in Sandbox Env.
Could you please help me on this?
Created 11-06-2023 12:28 AM
@user001,
I do not know what your Sandbox environment is, but I just tested with NiFi 1.15 and the solution works like a charm. So either you are doing something wrong, or you have something configured incorrectly in your sandbox environment. Or maybe NiFI 1.18 is bugged - but I highly doubt it, as there would have been far more posts reporting similar issues.