Generating documentation for serde_json types

I've got some enums and structs which my program loads from a JSON file, and I'd like to provide some documentation on the format of this file for users. I've searched through the serde and serde_json documentation, looked for crates on crates.io, and I couldn't find a way to do this.

Does anyone know of a way to generate a markdown document for the format out of the doc attributes on these types, variants and fields? Sort of like the way clap is able to generate documentation, and there are crates that can turn clap documentation into markdown, man page, etc.

If not, how about a crate that lets me programmatically extract the doc attributes from the types, and I could build this up myself? I'm sure that could be done with some proc-macros, so I'm hoping that someone else already has.

Right now, the best I can do is use rust-doc to generate a website for the API, but the audience are not (necessarily) rust programmers, and the JSON format ends up slightly different from the rust API.

Thanks for your help.

I believe you are looking for a JSON schema. An implementation of the JSON schema in Rust is schemars.

1 Like

This will help a great deal, yes. I hadn't even thought of looking for a schema crate. Thanks.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.