title: how to cleanly handle undefined values with a yaml dump (js-yaml)
body: <p>Using <a href="https://github.com/nodeca/js-yaml" rel="nofollow noreferrer">JS-YAML</a> but this probably applies to other YAML i/o libraries.</p>
  <p>I'm <code>dump</code> ing an object, and fields without values come out like this:</p>
  <p><code>fieldName: !&lt;tag:yaml.org,2002:js/undefined&gt; ''</code></p>
  <p>how can I suppress that to either <code>undefined</code> or just to skip it like <code>JSON.stringify</code> ? I guess what I want is to serialize something that would parse in again later, so I'm not sure what value. <code>undefined</code> seems to work for me with this typescript definition</p>
  <p><a href="https://i.stack.imgur.com/R8n80.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R8n80.png" alt="TSdef" /></a></p>
  <p>I tried some options from the <code>safeDump</code></p>
  <p><code>const blob = yaml.dump(obj, { skipInvalid: true, lineWidth: 200 })</code></p>
  <p><a href="https://github.com/nodeca/js-yaml#safedump-object---options-" rel="nofollow noreferrer">https://github.com/nodeca/js-yaml#safedump-object---options-</a></p>
  <p>but without success. I guess I can strip out the undefined fields, but I'd have to do a <code>deep</code> clean of the whole object... also check for <code>false</code> vs <code>undefined</code> etc. etc.</p>
  <p>I tried this but it didn't have any effect:
  <code>const clean = { ...obj } // remove nulls?</code></p>
  <p>Sure there must be a nicer way to handle this with <code>js-yaml</code> ?
  Do I have to define my own schema?</p>
  <p>related:
  <a href="https://github.com/nodeca/js-yaml/issues/456" rel="nofollow noreferrer">https://github.com/nodeca/js-yaml/issues/456</a>
  <a href="https://stackoverflow.com/a/38340374/1146785">https://stackoverflow.com/a/38340374/1146785</a></p>
  <pre class="lang-js prettyprint-override"><code>
    async debugMessage(obj) {
      console.log('json', JSON.stringify(obj, null, 2))
      const blob = yaml.dump(obj)
      console.log('yaml', blob)
    }
  
  
  // json 
  
  {
    &quot;msg&quot;: &quot;router&quot;,
    &quot;input&quot;: &quot;sleep&quot;,
    &quot;eventType&quot;: &quot;action&quot;,
    &quot;handled&quot;: {
      &quot;handled&quot;: true,
      &quot;doc&quot;: {
        &quot;match&quot;: &quot;^cont|.*&quot;,
        &quot;goto&quot;: &quot;prologue&quot;
      },
      &quot;klass&quot;: &quot;room&quot;,
      &quot;history&quot;: [
        &quot;goto&quot;
      ]
    }
  }
  
  // yaml 
  
  msg: router
  input: sleep
  eventType: action
  parsed: !&lt;tag:yaml.org,2002:js/undefined&gt; ''
  handled:
    handled: true
    doc:
      match: ^cont|.*
      goto: prologue
    klass: room
    history:
      - goto
  
  </code></pre>