3 ms·
It's basically the same for typed languages. If you want to map JSON to a typed data structure, you need a serialization library to do that. JavaScript has a v
by andix 3y ago
It's basically the same for typed languages. If you want to map JSON to a typed data structure, you need a serialization library to do that.
JavaScript has a very simple built-in json reader/writer that does no type checking and returns some nested dictionaries or arrays. If you want more, you need a library (for example zod). Or you just trust the data to have the right shape.
- jfengel 3y agoJava has runtime type definitions, which you can use to automatically type check deserialized objects. With reflection you can write that in ordinary Java. I imagine C# and other Java-esque languages have something similar. But Typescript deliberately avoids that, and it would be difficult to get it to do so.