Title: how to handle undefined values cleanly? · Issue #571 · nodeca/js-yaml · GitHub
Open Graph Title: how to handle undefined values cleanly? · Issue #571 · nodeca/js-yaml
X Title: how to handle undefined values cleanly? · Issue #571 · nodeca/js-yaml
Description: I'm dump ing an object, and fields without values come out like this: fieldName: !
Open Graph Description: I'm dump ing an object, and fields without values come out like this: fieldName: !
X Description: I'm dump ing an object, and fields without values come out like this: fieldName: !<tag:yaml.org,2002:js/undefined> '' how can I suppress that to either undefined or just to skip i...
Opengraph URL: https://github.com/nodeca/js-yaml/issues/571
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"how to handle undefined values cleanly?","articleBody":"I'm `dump` ing an object, and fields without values come out like this:\r\n\r\n`fieldName: !\u003ctag:yaml.org,2002:js/undefined> ''`\r\n\r\nhow can I suppress that to either `undefined` or just to skip it like `JSON.stringify` ?\r\n\r\nI tried some options from the `safeDump` \r\n\r\n`const blob = yaml.dump(obj, { skipInvalid: true, lineWidth: 200 })`\r\n\r\nhttps://github.com/nodeca/js-yaml#safedump-object---options-\r\n\r\nbut without success. I guess I can strip out the undefined fields, but I'd have to do a `deep` clean of the whole object... also check for `false` vs `undefined` etc. etc.\r\n\r\nI tried this but it didn't have any effect:\r\n`const clean = { ...obj } // remove nulls?` \r\n\r\nSure there must be a nicer way to handle this with `js-yaml` ?\r\nDo I have to define my own schema?\r\n\r\nrelated:\r\nhttps://github.com/nodeca/js-yaml/issues/456\r\nhttps://stackoverflow.com/a/38340374/1146785\r\n\r\n\r\n```js\r\n\r\n async debugMessage(obj) {\r\n console.log('json', JSON.stringify(obj, null, 2))\r\n const blob = yaml.dump(obj)\r\n console.log('yaml', blob)\r\n }\r\n\r\n\r\n// json \r\n\r\n{\r\n \"msg\": \"router\",\r\n \"input\": \"sleep\",\r\n \"eventType\": \"action\",\r\n \"handled\": {\r\n \"handled\": true,\r\n \"doc\": {\r\n \"match\": \"^cont|.*\",\r\n \"goto\": \"prologue\"\r\n },\r\n \"klass\": \"room\",\r\n \"history\": [\r\n \"goto\"\r\n ]\r\n }\r\n}\r\n\r\n// yaml \r\n\r\nmsg: router\r\ninput: sleep\r\neventType: action\r\nparsed: !\u003ctag:yaml.org,2002:js/undefined> ''\r\nhandled:\r\n handled: true\r\n doc:\r\n match: ^cont|.*\r\n goto: prologue\r\n klass: room\r\n history:\r\n - goto\r\n\r\n````\r\n","author":{"url":"https://github.com/dcsan","@type":"Person","name":"dcsan"},"datePublished":"2020-07-25T23:43:52Z","url":"https://github.com/nodeca/js-yaml/issues/571"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:66902c7e-5da6-9574-1d57-722b4b548589 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D322:23CD5:45B872:5DB0F4:6AEDB651 |
| html-safe-nonce | 96c4e3d1dd78d26054d4dd8a1da93805a8e95f284b983efc28bc62e10f6db431 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzIyOjIzQ0Q1OjQ1Qjg3Mjo1REIwRjQ6NkFFREI2NTEiLCJ2aXNpdG9yX2lkIjoiMTU0ODQwNjkyNjg1NDY5ODU3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 99fdcb35c494b2e2aa439cc6bd9ba7181d461681dbbf4a28185c992ac72bfd97 |
| hovercard-subject-tag | issue:665678692 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodeca/js-yaml/571/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d7e8bab38d62234fdba62231ad5481d2a13efeb8bde09c3213893fb0c64ab335/nodeca/js-yaml/issues/571 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d7e8bab38d62234fdba62231ad5481d2a13efeb8bde09c3213893fb0c64ab335/nodeca/js-yaml/issues/571 |
| og:image:alt | I'm dump ing an object, and fields without values come out like this: fieldName: ! |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dcsan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1eb5f7cedbc707472687eab1a30e6c4619c00791815622ceaba9694eb161930f |
| turbo-cache-control | no-preview |
| go-import | github.com/nodeca/js-yaml git https://github.com/nodeca/js-yaml.git |
| octolytics-dimension-user_id | 723678 |
| octolytics-dimension-user_login | nodeca |
| octolytics-dimension-repository_id | 2504175 |
| octolytics-dimension-repository_nwo | nodeca/js-yaml |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 2504175 |
| octolytics-dimension-repository_network_root_nwo | nodeca/js-yaml |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f31f9c89203c022acdb651c34ae048cf41764208 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width