diff --git a/src/cli.rs b/src/cli.rs index 21ac989..6063ab8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -214,8 +214,14 @@ fn fmt_msg_in(args: Vec) -> Result { bail!("too many arguments") } - let msg: yaml::Value = yaml::from_str(&msg)?; - let msg = json::to_string(&msg)?; + // Since we'll mostly by passing json using `-m`, and json is faster than yaml + // let's try to validate using json first. + let msg = if let Ok(val) = json::from_str::(&msg) { + json::to_string(&val)? + } else { + let val: yaml::Value = yaml::from_str(&msg)?; + json::to_string(&val)? + }; Ok(msg) }