3 ms·
> Want to read/write pretty-arbitrary JSON? Good luck Parsing JSON in Java was one of my worst programming experiences, so I have to agree with you here. But
by vurpo 10y ago
> Want to read/write pretty-arbitrary JSON? Good luck
Parsing JSON in Java was one of my worst programming experiences, so I have to agree with you here.
But in Rust, using the `rustc-serialize` library (and Serde, but I haven't tried that yet), parsing and writing JSON is really pretty painless. The really nice part is that you can declare the structure of your JSON data as a completely normal Rust struct (just with a derive annotation that makes it Encodable and/or Decodable), and with a single function call turn an instance of that struct into a JSON string. And in reverse, you can just parse() a string and it will return either an instance of your struct or an informative error if the JSON is malformed or doesn't match your structure. Makes JSON really easy to work with.
- bpicolo 10y agoI think 'arbitrary' was actually the key word. I agree that serializing/deserializing structs is pretty painless, the issue is when you're not sure what you're getting. In golang recently I had to take some json (that I only knew part of the structure of), and modify just that small subpart of it without touching the rest. It was a really painful thing to develop, and the code ended up very messy. There were a few golang libs for reading arbitrary json, but none supported writing to it that I could find.
- andrewaylett 10y agoJackson (in Java) gives you pretty much the same experience, albeit I'd recommend a few annotations on your object. And you can read/write arbitrary JSON into JsonNode or Map<> objects.