Confused about using serde json

So I am trying to work with some JSON data:

fn execute_get_item_command(
    item: option::Option<string::String>,
) -> Result<(), Box<dyn error::Error>> {
    // Check if item is set
    if item.is_none() {
        return Result::Err(Box::new(crate::command::MissingCommandError(
            "Missing item identifier flag (-i)".into(),
    let item_id = item.unwrap();

    // Create op command
    let cmd_output = process::Command::new("op")
    let stdout = match std::str::from_utf8(&cmd_output.stdout) {
        Ok(s) => s,
        Err(err) => return Result::Err(Box::new(err)),
    let stderr = match std::str::from_utf8(&cmd_output.stderr) {
        Ok(s) => s,
        Err(err) => return Result::Err(Box::new(err)),

    // Handle output from stderr as an error
    if !stderr.is_empty() {
        return Result::Err(Box::new(crate::command::CommandExecuteError(

    println!("{}", stdout);

This function basically calls “op” command, this command returns some big JSON string. Everything works fine so far, however when I try to implement serde to manipulate the JSON string into a custom struct I get:

error[E0107]: wrong number of type arguments: expected 1, found 2
–> src/command/
39 | ) -> Result<(), Box> {
| ^^^^^^^^^^^^^^^^^^^^^ unexpected type argument

The only thing that changed is me adding:

use serde::{Deserialize, Serialize};
use serde_json::Result;

#[derive(Serialize, Deserialize)]
struct OpItem {
    uuid: String,
    vaultUuid: String,

And adding the following to my Cargo.toml file:

serde_json = "1.0"
serde = { version = "1.0.91", features = ["derive"] }

If I remove those lines I added, everything works fine (I get to see the JSON output from the command stdout). I am new to Rust so maybe its something very basic I am missing?


when you imported serde_json::Result rust thinks that when you type Result<(), Box> you mean serde_json::Result<(), Box> but that is probably something like serde_json::Result<T> so it gives an error, maybe use it with fully qualified name instead of importing it

1 Like

That worked, thank you.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.