You can have a one-liner class like
class Person(val name: String, val email: String, val yearOfBirth: Int? = null)
Or you can make it a `data class` and get automatic `equals` and other things.When I suggest switching to Kotlin everyone's always smiling dismissively like "ah, you with your crazy ideas again".
Might do it though. Maybe.
To me, it's much better to let every company send error messages in the format that makes sense to them rather than having the One True Error that doesn't quite work for anyone.
My biggest complaints about JSON are syntactic. Optional comments, multi-line strings, and trailing commas would do wonders for day-to-day readability without significantly bloating the specs.
With respect to your "lack is strength" argument, I can't help but find this unconvincing. We all know JSON is derived from JavaScript object/array literal syntax; your argument is akin to retro-fitting the requirements for service payload serialization to the suboptimal de-facto situation with JSON.
I miss the "and a project which doesn't use modern standards"-part in your post. It's not as if JSON or other modern things are not used in many Java projects. Your project seems to be stuck in the past, as are many JS projects. Legacy code is no fun most of the time.
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.
Implementing j`{"key":"value"}`; as a tagged template literal is left as an exercise for the reader.
Is there any serialisation standard that specifically addresses this? I know YAML and TOML doesn't at least (correct me if I"m wrong)
No more trying to have short names to keep file size down.
https://blog.octo.com/en/protocol-buffers-benchmark-and-mobi...
The primary purpose of binary data formats is that they can be parsed quickly and some even allow direct access without a parsing step.
Whereas javascript you can just go `require(myjsonfile)`
I love java, but Javascript is indeed great for some of these kinds of things :-)
I'm not current on Node features, but that looks dangerous to do. Is that equivalent to reading the file and `eval()`ing it?
No:
> const fs = require('fs')
undefined
> fs.writeFileSync('file.js', 'console.log("yes")'); require('./file')
yes
{}
> fs.writeFileSync('file.json', 'console.log("no")'); require('./file.json')
SyntaxError: file.json: Unexpected token c in JSON at position 0JSON5 is something that should've been.
The biggest reason for JavaScripts greatness to me is JSON. I couldn't understand how Java developers put up with such bulky ways to deal with data. After some time in Java land I've come back to appreciating its strengths again though. Code completion is nice. I'm kind of hoping for more typescript in the future.