3 ms·
It seems you're not talking about JSON (the serialization format) but rather about Javascript's object literal syntax that inspired JSON. They're really differe
by Scarblac 8y ago
It seems you're not talking about JSON (the serialization format) but rather about Javascript's object literal syntax that inspired JSON. They're really different things.
- wyattpeak 8y agoPerhaps, but probably not. ES6 recognises the distinction, and includes native functions for serialisation. That's first-class treatment if anything is.
- Scarblac 8y agoJSON.stringify and JSON.parse? They're standard library functions that many languages have, I don't see what's ES6 about them, they're much older. First class treatment would be if the language had JSON-typed objects with functionality, e.g. something like const myJson = j'{"key":"value"}'; const value = myJson['key']; const newJson = myJson.set("otherkey", "newValue"); (using the j'' notation for a hypothetical json-typed value) But AFAIK it doesn't, not even in ES6.
- brlewis 8y agohttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Implementing j`{"key":"value"}`; as a tagged template literal is left as an exercise for the reader.
- Vinnl 8y agoAn advantage, however, is that you can directly encode Javascript data objects to JSON without having to annotate its fields or anything. I don't recall you being able to do that with Java.
- imtringued 8y agoYou can't do that with javascript either unless your data objects are acyclic and if they are then using a JSON parser for Java is equally trivial.
- Vinnl 8y agoYou mean that if they are acyclic, you don't have to annotate the fields in Java either? Because the data objects I want to serialize usually are acyclic.
- deleted 8y ago[deleted]