-
Notifications
You must be signed in to change notification settings - Fork 61
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
JsonParser should be capable of parsing keys not surrounded by " #262
Comments
The above example currently results in: |
One can achieve equivalent shorter JSON using an array of numbers instead, but if the usecase requires only a AbstractMap.SimpleImmutableEntry, then it's better to use that rather than an array of numbers for maintainability purposes, etc. |
Of course the same should be applicable to the writing side: JSON should be optimized there first. |
The approach i like currently requires custom P.S. The current implementation is not optimized enough with regards to both writing & reading. |
But ECMA-404 says: A string is a sequence of Unicode code points wrapped with quotation marks (U+0022).
What do you mean by JS?
Firefox:
Chromium:
|
Good point: this enhancement in jsonp would require & depend on a similar enhancement in JSON.parse(...). So i guess this would be a long-term thing, if it ever happens.
I meant plain JS, not JSON.parse(...) functionality. E.g.: var m2={
10729945:{null:2},
10730556:{1:null},
10729026:{3:null}
};
console.log(m2);
var keys0 = Object.keys(m2[10729945]);
console.log(keys0); // Array [ "null" ]
console.log(typeof keys0[0]); // string
var keys1 = Object.keys(m2[10730556]);
console.log(keys1); // Array [ "1" ]
console.log(typeof keys1[0]) // string P.S. My point is: since JSON is based on JS, what's conventional in JS should be acceptable in JSON, & in its parsers. Imagine how many bytes around the known universe could be removed from network traffic & CPU workloads. That would be a good thing. |
Of course Java-to-Java communication could start benefiting from that without depending on JSON.parse(...) in JS. But perhaps that would require a config setting like P.S. I made the JS example above a little more legible (spacing & 2 more variables). |
FWIW, this is a request to generate/accept invalid JSON. |
IMHO, one can view this as being about progress vs. status quo (& it's not at all natural that JSON requires extra characters that equivalent JS code doesn't (1 could also argue that it's a bug in JSON spec/implementation)):
|
JSON is supposed to be interoperable. There are many things that I dislike in JSON (and would change if I could), but if you really want to change JSON, you'll need to engage with ECMA and IETF. Experimenting with changes to JSON is fine, but by all means don't call it "JSON" anymore. |
See https://json5.org/. I suppose someone could create a configuration flag. |
JsonParser should be capable of parsing keys without ", assuming that they are of type String (as is done in JS), rather than rejecting them and requiring them to be surrounded with ".
As in:
"{\"10729945\":{2:null},\"10730556\":{1:null},\"10729026\":{3:null}}"
P.S. The benefit is 2 bytes less per key (e.g., 1 vs. "1") used in network traffic, thus making a small performance & bandwidth usage optimization, that would make a lot of apps better at once (given that this is a very generic thing).
The text was updated successfully, but these errors were encountered: