title: How to write an object to the stream?
body: <p>I'm trying to write an object to the stream:</p>
  
  <pre><code>const fs = require('fs');
  
  const stream = fs.createWriteStream('index.json', {objectMode: true});
  stream.write({"a":1});
  
  stream.end();
  </code></pre>
  
  <p>According to the <a href="https://nodejs.org/api/stream.html#stream_constructor_new_stream_writable_options" rel="nofollow noreferrer">documentation</a>, I can do it, passing option <code>{objectMode: true}</code>, but I'm getting an error:</p>
  
  <pre><code>events.js:182
        throw er; // Unhandled 'error' event
        ^
  
  Error: Invalid data
      at WriteStream._write (fs.js:2116:31)
      at doWrite (_stream_writable.js:385:12)
      at writeOrBuffer (_stream_writable.js:371:5)
      at WriteStream.Writable.write (_stream_writable.js:288:11)
      at Object.&lt;anonymous&gt; (/Users/rostik404/projects/test-project/test-stream.js:8:8)
      at Module._compile (module.js:573:30)
      at Object.Module._extensions..js (module.js:584:10)
      at Module.load (module.js:507:32)
      at tryModuleLoad (module.js:470:12)
      at Function.Module._load (module.js:462:3)
  </code></pre>
  
  <p>Version of node is <code>8.4.0</code></p>