Greg,

I would probably ScriptedTransformRecord in this case and script a solution 
that looks at the value and determines which pattern to use.

Thanks
-Mark

> On Feb 25, 2021, at 9:35 AM, Gregory M. Foreman 
> <[email protected]> wrote:
> 
> Hello,
> 
> I am attempting to parse timestamps of various formats/precision within the 
> same field in json.  Here is an example (using Nifi 1.11.4):
> 
> input:
> 
> {"cd": "2021-02-24T12:01:01"}
> {"cd": "2021-02-24T12:01:01Z"}
> {"cd": "2021-02-25T12:01:01.99"}
> {"cd": "2021-02-26T12:01:01.999"}
> 
> conversion in UpdateRecord:
> 
> /cd = format(toDate(/cd, "yyyy-MM-dd'T'HH:mm:ss"), 
> "yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
> 
> output:
> 
> {"cd":"2021-02-24T12:01:01.000+0000"}
> {"cd":"2021-02-24T12:01:01.000+0000"}
> {"cd":"2021-02-25T12:01:01.000+0000"} << precision lost
> {"cd":"2021-02-26T12:01:01.000+0000"} << precision lost
> 
> changing the conversion in UpdateRecord to this:
> 
> /cd = format(toDate(/cd, "yyyy-MM-dd'T'HH:mm:ss.SSS"), 
> "yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
> 
> output:
> 
> {"cd":"2021-02-24T12:01:01"}  << skipped
> {"cd":"2021-02-24T12:01:01Z"} << skipped
> {"cd":"2021-02-25T12:01:01.099+0000"} << not sure if this is correct
> {"cd":"2021-02-26T12:01:01.999+0000"} << correct
> 
> 
> Is there a way to change the timestamp parsing format on a per-record basis?
> 
> Thanks,
> Greg
> 

Reply via email to