Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Convert TXT to JSON using Schema counting chars

avatar
Contributor

Hello,

with this topic i need a clue.

 

I have a text based data, this is an example row:

 

CA20230405112337BOL006057 20230405V1260     2023021000409I     311003000102504

CA20230405112337BOL006057 20230405V1260     2023021000509I     311003000102504

 

I need to convert to json but:

1  - i need to remove all spaces in between

2 - i need to separate fields with a separator in order to create a schema and make a conversion

Example:

CA;20230405;bla bla bla

CA;20230405;bla bla bla

 

How can i achieve this?

Is there any other way to do that?

 

Many Thabks

 

1 ACCEPTED SOLUTION

avatar

hi @Ray82,

Assuming that you have a way to identify where you need to add your ";", you can easily use NiFi's Expression Language to add it. More details are available here: https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html.

 

At first sight, if you identify a pattern, you can use any function with replace in order to replace your white space with semicolon. Next, to add the semicolon between your characters, you can use an regex, based on your pattern. In terms of processors, you have ReplaceText, UpdateAttribute, UpdateRecord, etc .... so you have plenty to choose from 🙂

View solution in original post

1 REPLY 1

avatar

hi @Ray82,

Assuming that you have a way to identify where you need to add your ";", you can easily use NiFi's Expression Language to add it. More details are available here: https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html.

 

At first sight, if you identify a pattern, you can use any function with replace in order to replace your white space with semicolon. Next, to add the semicolon between your characters, you can use an regex, based on your pattern. In terms of processors, you have ReplaceText, UpdateAttribute, UpdateRecord, etc .... so you have plenty to choose from 🙂