Skip to content

Conversation

@jannschu
Copy link

Hi,

the --input and --data parameters for the CLI are delcared as:

struct Cli {
    // ...
    /// JSON literal to use as data
    #[arg(short, long = "data", group = "data", value_name = "JSON")]
    data_value: Option<serde_json::Value>,

This results in unexpected parsing behavior.

With this declaration clap's value_parser defaults to the From<String> implementation for serde_json::Value to convert the provided argument. The From<String> always results in serde_json::Value::String(...), it does not parse a string containing serialized JSON data, which is not intended I assume.

This, to the best of my knowledge, does prevent users from specifying a JSON object, everything will be treated as a string.

I added a explicit value_parser attribute such that serde_value::from_str is used, which tries to parse a string (unfortunate naming maybe in this context).

# before: parsed as "{}", a JSON string
# with this PR: parsed as {} a JSON object
-i "{}"

Signed-off-by: Jannik Schürg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant