js-yaml icon indicating copy to clipboard operation
js-yaml copied to clipboard

Redundant quotes added

Open coderaiser opened this issue 3 years ago • 2 comments

const yaml = require('js-yaml');

const file = `
  name: Node CI
  on:
    - push
`;

const json = yaml.load(file);
console.log(yaml.dump(json));

Output:

name: Node CI
'on':
  - push

coderaiser avatar Oct 28 '21 07:10 coderaiser

on without quotes is a boolean true value in YAML 1.0, old version of the spec: https://yaml.org/type/bool.html

so it's intentional, but we probably should drop support for that at some point

rlidwka avatar May 09 '22 13:05 rlidwka

The solution for now is to use noCompatMode as explained in other issue.

yaml.dump(json, {noCompatMode: true});

https://runkit.com/abitrolly/62f3a3ccbc61df0008be5b4e

abitrolly avatar Aug 10 '22 12:08 abitrolly