Skip to main content
Question

Format Text File where Column Names are Repeated on Each Row


tim.albert.vaa
Contributor
Forum|alt.badge.img+9

I have a text file that looks like this:

"CommonCode":"EI","IATA":"EI","ICAO":"EIN","CarrierName":"Aer Lingus"
"CommonCode":"AM","IATA":"AM","ICAO":"AMX","CarrierName":"Aeromexico"

I want it to look like this:

CommonCode IATA ICAO CarrierName
EI EI EIN Aer Lingus
AM AM AMX Aeromexico


I want it to create the column names dynamically from the text file as the column names will change and increase or decrease in number.

In R there appears to be a command called:  “unsparsify”   Which according to this post seems to do it.https://datascience.stackexchange.com/questions/55879/file-format-where-column-names-are-repeated-on-each-row

I can do it using a combination of AttributeSplitters, ListExploders, ListIndexers, AttributePivoters and AttributeExposers.   But I can’t seem to get away from having to Explicitly input the Attribute names in the AttributeExposer and I need it to be dynamic.

Any ideas?

3 replies

DanAtSafe
Safer
Forum|alt.badge.img+16
  • Safer
  • March 21, 2025

Hi Tim, Did you try a SchemaScanner? You don’t need to expose attributes for dynamic writing. 

I got this written out to Excel: 

Note that the fields are sorted alphabetically.


mark2atsafe
Safer
Forum|alt.badge.img+43

Nice ​@DanAtSafe - are you going to add this to the FME Hub as a new transformer?!


crutledge
Enthusiast
Forum|alt.badge.img+27
  • Enthusiast
  • March 21, 2025
mark2atsafe wrote:

Nice ​@DanAtSafe - are you going to add this to the FME Hub as a new transformer?!

I vote yes! This is an elegant solution. Something I will definitely use down the road (or run into and have to solve at that point :D)


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings