jeremyfa / yaml.js

Standalone JavaScript YAML 1.2 Parser & Encoder. Works under node.js and all major browsers. Also brings command line YAML/JSON conversion tools.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

yamljs.parse can't handle valid JSON

souenzzo opened this issue · comments

commented

Hello

I'm porting a service from JVM to Nodejs

This services handles YAML and for history reasons, it still have to handle some JSON.

I expect that the YAML parser can handle any JSON, as the JVM lib that I use on JVM do.

This lib handle some JSON, but not any JSON (in general, pprint'ed JSON dosen't work)

https://yaml.org/
- 08-APR-2005 -- As it turns out, YAML is a superset of the JSON serialization language

node: v15.1.0

yamljs: v0.3.0

Example data:

{
  "a": 42
}

One-line reproduce:

node -e "console.log(require('yamljs').parse(JSON.stringify({a: 42}, null, 2)))"

Current output:

$ node -e "console.log(require('yamljs').parse(JSON.stringify({a: 42}, null, 2)))"

/home/souenzzo/.../node_modules/yamljs/lib/Parser.js:267
            throw e;
            ^
/home/souenzzo/.../node_modules/yamljs/lib/Parser.js:267
            throw e;
            ^
[ParseException [Error]: Malformed inline YAML string ({
  "a": 42
}).] {
  parsedLine: 1,
  snippet: '{'
}

Expected output

$ node -e "console.log(require('yamljs').parse(JSON.stringify({a: 42}, null, 2)))"
{ a: 42 }