Crate json_arg

source ·
Expand description

CLIs (especially those designed to be called by automation) often take JSON data as inputs. This ends up creating a ton of boilerplate where a CLI arg is declared as a PathBuf and then is quickly opened, read from and deserialized with serde_json. This crate provides two newtype wrappers (Json and JsonFile) that can deserialize JSON arguments with no extra effort.

Structs

Inline JSON string. The argument provided by the caller is the raw JSON string (and the caller must consequently deal with shell quoting ahead-of-time).
Argument that represents a JSON file. The argument provided by the caller is the path to the JSON file that is deserialized immediately on load. The original path is preserved and accessible with JsonFile::path