HACKER Q&A
📣 dpkrjb

Tools to declare typed structs across languages


Hi HN, Can someone help point me in the right direction? I'm looking for a tool to simplify the code generation of typed structs across platforms. This (boring) tool would allow me to:

1. Declare the schema of many data types

2. Use the schema to generate structs from those data types in multiple languages (Golang, Typescript, Dart)

3. Easily serialize and deserialize those types to and from JSON

My Google-fu seems to be pretty awful because I cannot find a single tool that allows me to declare a type schema without it also being an alternative to JSON.

Any boring solutions out there?


  👤 orbz Accepted Answer ✓

👤 nerpderp82
Is json a hard requirement?

https://capnproto.org/otherlang.html allows for a serialization free solution.


👤 tantony
XML is old-school, but it works. Any program that processes the XML schema can validate them using XSD files. Repetition can be avoided using extensions like xpath and xinclude.