Skip to content

Automatic type detection and optional quotes #1

Description

@burningtree

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions