Skip to main content
Solved

Writing JS file with JSON writer


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!

Best answer by ctredinnick

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)

View original
Did this help you find an answer to your question?

4 replies

ctredinnick
Supporter
Forum|alt.badge.img+18
  • Supporter
  • Best Answer
  • December 1, 2022

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...

 


ctredinnick
Supporter
Forum|alt.badge.img+18
  • Supporter
  • December 2, 2022
potatocomputer wrote:

@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?


ctredinnick wrote:

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


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