5 ms·
JSON is seldom JS now, as any language has had encoder/decoder built in for years.
by sametmax 8y ago
JSON is seldom JS now, as any language has had encoder/decoder built in for years.
- alephnan 8y agoSure, but there is boilerplate and abstractions that are needed in a language like Java or Scala. In JavaScript, it's a first-class citizen of the language.
- Scarblac 8y agoIt 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]
- Sean1708 8y agoIsn't comparing JS to something like Java or Scala a bit misleading in this regard? They're completely different styles of language with different tradeoffs. I think it would be a lot more fair to compare to something like Python or Ruby, in which case this advantage become a lot less clear IMO.
- sametmax 8y agoWell you must compare a dynamic language with another dynamic language. It would be more fair to compare JS to Python or Ruby if you talk about ease of use.