Skip to main content
Solved

Writing JS file with JSON writer

  • December 1, 2022
  • 4 replies
  • 48 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!

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)

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

ctredinnick
Supporter
Forum|alt.badge.img+19
  • Supporter
  • 225 replies
  • 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)


  • Author
  • 2 replies
  • December 2, 2022

@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+19
  • Supporter
  • 225 replies
  • December 2, 2022

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


  • Author
  • 2 replies
  • December 2, 2022

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