3 ms·
Yeah we are on the same page, lol. Practical usage isn't as sexy as diehard ideological arguments. That said, what JSON corresponds to doesn't matter -- you're
by galdosdi 3y ago
Yeah we are on the same page, lol. Practical usage isn't as sexy as diehard ideological arguments.
That said, what JSON corresponds to doesn't matter -- you're parsing it into a data structure that makes sense for your use case. You do not need to represent arbitrary JSON, and should not -- only valid values. So maybe that means something like
struct Person {
String name;
int age;
enum Country birthplace;
Map<String,String> other attributes;
}
I am baffled by the purists who act like this is somehow not allowed.
Or if you genuinely are just building a generic JSON parsing library, that's easy enough as you described. The pseudo BNF definition of JSON is simply mapped directly to sum and product types. I have worked on (very lightly) a popular java Json library (Jackson) and it was no problem...
Another problem is lately there are novice people whose only exposure to type systems is, of all things, typescript (or pep484 python) which is a horrible example of a practical type system because (much like pep484) it's been bolted on poorly onto an existing typeless language.