Is there a parser / encoder for JavaScript object literals without JSON restrictions?

Well, after the “discussion” here:

https://stackoverflow.com/questions/5281903/java-json-parsers-whats-the-abusive-anal-thing-with-the-quote-marks-on-attribu

Is there a parser / decoder for JavaScript object literals without JSON restrictions?

EDIT

In my initial post, I said that I work with Java-end. I marked it with .net because I come from a .net background and can use their support - and that turned out to be correct. They knew what I was talking about, and with all the porting between the two languages ​​- I was hoping to hear something new.

The back of Java needs to read this "light" version of JSON and provide it. Thus, this is both Parser and Encoder. (I set the title name, sory for confusion)

+3
source share
1 answer

The fact that the “insulting anal thing with quotes around attribute names,” as you call it, is the result of Douglas Crockford’s decision to greatly simplify the JSON format and make JSON parser entries much easier .

, JavaScript : break, case, catch, class, const, continue, debugger, default, delete, do, else, enum, export, extends, false, , , , if, , , in, instanceof, , let, new, null, package, private, protected, public, return, static, super, switch, this, throw, true, try, typeof, var, void, while, with yield, .

, JavaScript.

" " JavaScript- , , JavaScript-.

UPDATE:

, - , JSON- , JSON ( ), , JSON .

, , SDXF (RFC 3072 - ) BSON ( JSON, - JSON- ) , JSON (, 1% gzipped- ).

2:

, JSON, :

[{"a":1,"b":2,"c":3,"d":4},null,null,{"a":9,"b":10,"c":11,"d":12}]

66 . JavaScript, :

[{a:1,b:2,c:3,d:4},,,{a:9,b:10,c:11,d:12}]

42 . ( , - , [1,,2,,] 4 - Firefox , , 5- IE.)

, . , :

a1b2c3d4,,,a9b10c11d12

22 . , . , . , CFON Compact Flat Object Notation.

JSON, :

var inp = input.split(','),
    out = [], i, j, m, p, output;
for (i = 0; i < inp.length; i++) {
    if (inp[i]) {
        out[i] = {};
        m = inp[i].match(/[a-z]+\d+/ig);
        for (j = 0; j < m.length; j++) {
            p = /([a-z]+)(\d+)/i.exec(m[j]);
            out[i][p[1]] = p[2];
        }
    }
}
output = JSON.stringify(out);

. CFON → JSON DEMO.

JSON , :

var inp = JSON.parse(input),
    out = [], i, k, output;
for (i = 0; i < inp.length; i++) {
    out[i] = '';
    if (inp[i]) {
        for (k in inp[i]) {
            if (inp[i].hasOwnProperty(k)) {
                out[i] += k + inp[i][k];
            }
        }
    }
}
output = out.join(',');

. JSON → CFON DEMO.

, , CFON. - , .

, . , , . , , . , - , .

+8

All Articles