Closed gwc4github closed 8 years ago
Remove the '
... i.e. you're writing a string instead of an object. Please reopen if you're still unsure of what's going on.
Thanks JP. That does allow me to create some files but only complete objects. However, the JSON I am generating appears to be too big and kills writeFileSync(). Or maybe there is another issue I am not yet aware of. I can format the JSON in a text editor so I think it is ok. Here is the error: _stream_writable.js:260 var len = state.objectMode ? 1 : chunk.length; ^ TypeError: Cannot read property 'length' of undefined
Would you consider adding a flag so that we can use it to write text? That way I can build the JSON bit-by-bit. I suppose others might want to use if for text files too?
Thanks again JP
That does allow me to create some files but only complete objects.
What do you mean by "complete objects"? Do your objects contain a large amount of data? Are you trying to write out multiple objects, one per line?
I am building the objects from metadata and data that I am getting from other sources. So, this string is the start of a large object that I want to generate but is not yet complete: "'{ "type":"configuration/entityTypes/HCP", \n"attributes"" So, I could have tried to write the code to keep adding to objects and arrays instead of building a string but that was harder to do in some cases. Maybe I should have done it that way anyway but this seems easier to debug? the code currently creates a large object in memory as a string. I tried writing that out with your function as shown and that didn't work. I also tried the standard fs.createWriteStream() and right now that fails too. It's about 49k in size.
If you're writing large amounts of data, fs.createWriteStream()
is what you want. If that's failing, there's some other issue going on.
Hello JP. Thanks for providing you jsonfile package. I have been trying to use your jsonfile package and I am having an interesting problem. This code:
jsonfile.writeFileSync('/tmp/gregg.dat', '{ "type":"configuration/entityTypes/HCP", \n"attributes": {\n');
Writes this:"{ \"type\":\"configuration/entityTypes/HCP\", \n\"attributes\": {\n”
instead of:{ "type":"configuration/entityTypes/HCP”, “attributes”: {
Am I doing something wrong?