Solved

Writing JS file with JSON writer

  • 1 December 2022
  • 4 replies
  • 6 views

I am trying to read in a csv and write the contents into a javascript file. It works at least 90% of the way and looks like this when I export the features:

[ { feature1: value1, feature2: value2 }, { .... } ] 

I would like to insert the text "var data = " at the beginning of the file, like so:

var data =[ { feature1: value1, feature2: value2 }, { .... } ] 

Is it possible to insert this text in the file before the JSON writer writes out the contents?

 

 Another detail is that this CSV file has over 5 million rows. It is difficult to open the file and write in the text or use powershell commands. Any help is appreciated!

icon

Best answer by ctredinnick 1 December 2022, 09:51

View original

4 replies

Userlevel 3
Badge +16

Unfortunately the JSON writer doesn't have a parameter of 'Overwrite Existing File', else this would be easy.

You can do something like this:

imageIn this setup, the Creator/AttributeCreator runs first to add the first line. The FeatureWriter is JSON. The FeatureReader reads it back in as TXT, which is set to Read Whole File At Once (this should perform well despite the file size)

@ctredinnick​ Thanks so much for the reply!

unfortunately I ran into an error: 

FeatureReader_text_line Feature Recorder -1 2147876877 (RecorderFactory): Failed to seek to beginning of `C:\Users\kr575h\AppData\Local\Temp\wb-cache-jonathan_script-oIodbU\Main_FeatureReader -1 13 fo 1 text_line  0  067d9964c396c76b3ea799ca2076faf8554d2ef3.ffsupdating' -- perhaps there is not enough disk space

This is strange to me since I definitely have enough disk space on my hard drive...

 

Userlevel 3
Badge +16

@ctredinnick​ Thanks so much for the reply!

unfortunately I ran into an error: 

FeatureReader_text_line Feature Recorder -1 2147876877 (RecorderFactory): Failed to seek to beginning of `C:\Users\kr575h\AppData\Local\Temp\wb-cache-jonathan_script-oIodbU\Main_FeatureReader -1 13 fo 1 text_line  0  067d9964c396c76b3ea799ca2076faf8554d2ef3.ffsupdating' -- perhaps there is not enough disk space

This is strange to me since I definitely have enough disk space on my hard drive...

 

Turn off feature caching for this if you have it on. It'll be saving a copy of the data at each transformer. I didn't think about the ordering, maybe it doesn't work with the two writers being the same file?

Turn off feature caching for this if you have it on. It'll be saving a copy of the data at each transformer. I didn't think about the ordering, maybe it doesn't work with the two writers being the same file?

turning off feature caching worked! thank you so much!!

Reply