During code generation, capnp already turns your .capnp files into a datastructure that it represents as a capnp message. You can convert that capnp message to json, maybe with a 'capnp decode' step if you prefer to operate on the text version of the message. This also has the benefit that if you turn the json into a capnp message, you can run the code generators on it.
On Friday, November 6, 2015 at 5:23:51 PM UTC, [email protected] wrote: > > Hi there, > > I'm new to Capn' Proto (impressive work!), and binary protocols generally, > coming from the world of web dev and JS. > > We define various models in our system with Capn' Proto schemas. We'd like > to keep these nicely typed definitions, but one of our use cases now calls > for working with simple JSON objects instead of Capn' Proto messages. > > E.g. for the Person example on <https://capnproto.org/language.html>, the > equivalent JSON object might be: > > { > "name": "Alice Smith", > "birthdate": {"year": 1980, "month": 6, "day": 15}, > "email": "[email protected] <javascript:>", > "phones": [{"number": "123-456-7890", "type": "mobile"}] > // not sure yet exactly how we'll translate enums like Type > } > > We ideally wouldn't duplicate all the schema definitions in e.g. JSON > Schema, and we'd ideally not write the code by hand to generate (from capnp > schemas) and validate (against capnp schemas) JSON objects. (In either > case, we'd have to manually keep something in sync with the capnp schemas.) > > So ideally, there would be e.g. codegen tools for doing those things... > but I don't think I'm finding any! E.g. the JS libs seem to be only about > reading and writing capnp *messages*. > > I'd guess this use case isn't new, so I'm very likely missing something > obvious as a beginner. Please feel free to point me in any direction. =) > > Thank you very much! > > Aseem > > -- You received this message because you are subscribed to the Google Groups "Cap'n Proto" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. Visit this group at https://groups.google.com/group/capnproto.
