Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yamljs.parse can't handle valid JSON #138

Open
souenzzo opened this issue Nov 17, 2020 · 0 comments
Open

yamljs.parse can't handle valid JSON #138

souenzzo opened this issue Nov 17, 2020 · 0 comments

Comments

@souenzzo
Copy link

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 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant