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

Automatic type detection and optional quotes #1

Open
burningtree opened this issue Apr 9, 2015 · 0 comments
Open

Automatic type detection and optional quotes #1

burningtree opened this issue Apr 9, 2015 · 0 comments

Comments

@burningtree
Copy link
Owner

Current behavior is in spirit of automatic type detection with optional quotes. Features exactly the same behavior as uses YAML:

(note: comma in uson can be replaced by whitespace, but for comparison, I did not do it)

var uson = require('./');
var yaml = require('js-yaml');
var assert = require('assert');

var str = '[ true, false, null, 1, 12.34, string, undefined, NaN, Number, "false" ]';
console.log(JSON.stringify(uson.parse(str, 'json')));
console.log(JSON.stringify(yaml.load(str)));
console.log(assert.deepEqual(uson.parse(str, 'json'), yaml.load(str)) ? false : true);

Returns:

[ true, false, null, 1, 12.34,  "string", "undefined", "NaN", "Number", "false" ]
[ true, false, null, 1, 12.34,  "string", "undefined", "NaN", "Number", "false" ]
true

But as pointed ZyklusDieWelt on reddit (source), it's ambiguous. You have to memorize that undefined gets set to a string and null to null.

Does anyone have a idea how to solve this problem? eventually, its a big problem for you?

Example of YAML shows that it works relatively good without problems, and if we want to save characters for typing, its a reasonable compromise for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant