Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
One of the reasons I love C# (in .net core, not .net framework/standard) is how nicely it plays with JSON.
class Person {
string? Name { get; set; }
}
...
try {
var person = JSONSerializer.Deserialize<Person>(string);
}
catch (JSONParseError jpe) {
Console.WriteLine("That's not a fucking person!");
} -
@AlgoRythm Obligatory Rust plug :P
#[derive(Deserialize)]
struct Foo {
#[serde(rename = "qux")]
pub is_qux: bool,
#[serde(default)]
pub list: Vec<Bar>,
}
let x = serde_json::from_str::<Foo>("...");
One of the most beautiful things i've ever used. It's so flexible and compatible with pluggable formats -
kobenz9582dInsanity aside, that dude did write the smallest compiler I have EVER had the displeasure of reading -
Swift
```
struct Person: Codable {
let name: String?
}
let person = try? JSONDecoder().decode(Person.self, data: jsonData)
```
This works with other formats as well, by using different decoders like XML or INI, etc.
And it‘s completely customizable. You can change naming like CamelCase or snake_case (useful for encoding), pretty printed with line breaks or compact single line, encoding/decoding rules for specific types like dates, and you get rich and detailed error messages telling you exactly what is wrong. -
kamen67792dThat must be just someone who's doing an exercise on TS types - because there's quite a lot that can be done on the type level. I see nothing wrong with that.
-
@Lensflare @TeachMeCode I bet neither of you know that you can play doom using the typescript type system, it's incredibly powerful. I don't think there is even a comparative system out there
@AlgoRythm @12bitfloat @Lensflare Not what this does -
@BordedDev I mean it parses json via the type system from a generic parameter, does it not? Either way this is cursed lol
-
@BordedDev that’s pretty cool actually. I had no idea you can do that and I’ve had two jobs that used typescript lol. That plus I like playing doom games
-
@BordedDev I have no doubt that it’s powerful.
And being able to run doom isn’t special. Anything that‘s Turing complete can run doom. -
@Lensflare And yet your mom still struggles. It's pretty special when it comes to type systems.
@12bitfloat It makes the type the parsed json, which is not what your code does -
TeachMeCode542923hAll I know about doom is shredding monsters with chainguns and bfgs is hella fun

oh boy
import type { ParseJson } from "json-parser-in-typescript-very-bad-idea-please-dont-use"
type Person = ParseJson<'{ "name": "Jamie Kyle", "twitter": "https://twitter.com/buildsghost" }'>
// {
// "name": "Jamie Kyle",
// } & {
// "twitter": "https://twitter.com/buildsghost"
// }
rant