Forum Discussion

Former Member's avatar
Former Member
2 years ago

CLI still has a bug when running "op create" programmatically

I am running "op create" programmatically and I get an error saying

[ERROR] 2023/12/06 11:47:57 invalid JSON in piped input

This was reported before https://1password.community/discussion/128994/failed-to-create-item-invalid-json, and marked as fixed, but I am using version 2.23.0 and I can still experience this.

Here's my Dart code:

const itemName = 'retrievable generated password';
final passwordCreationResult = processManager.runSync([
'op',
'item',
'create',
'--title="$itemName"',
'--category=password',
'--generate-password',
]);
print(passwordCreationResult.stdout.toString());
print(passwordCreationResult.stderr.toString());


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Browser: Not Provided

6 Replies

  • I've encountered a similar issue while attempting to programmatically create new entries using the 'op item create' command in the 1Password CLI version 2.27.0. I'm coding the application in Java. Facing similar challenges as others, depending on how I invoke the 'op item create' command, it either times out or returns an error message stating 'invalid JSON in piped input'. I've tested on both Windows and Linux, spending an entire day troubleshooting. Eventually, I found a solution to properly use the 'op item create' command in Java.

    I had to redirect the input to null output using ProcessBuilder:

    java
    ProcessBuilder processBuilder = new ProcessBuilder("op", "item", "create", "--category", "login", "--dry-run", "--format", "json");
    Map<String, String> env = processBuilder.environment();
    env.put("OP_SERVICE_ACCOUNT_TOKEN", "xxxx");
    processBuilder.redirectInput(ProcessBuilder.Redirect.from(new File(System.getProperty("os.name").startsWith("Windows") ? "NUL" : "/dev/null")));
    Process proc = processBuilder.start();

    This resolved the issue for me.

  • eM_Jay_Be's avatar
    eM_Jay_Be
    New Contributor

    I am also experiencing a similar issue with a project. It's not quite the same, mine involves the QProcess class in a Qt/QML app. All other commands I use work fine, including delete. Tried adding closeWriteChannel() as it seemed similar to above workarounds but to no avail. Haven't tested with edit yet.

  • Former Member's avatar
    Former Member

    I am experiencing this as well. It happens when my bash script is accepting input from stdin.

    Workaround is to close stdin, e.g.:

    ```

    !/bin/bash

    0<&- # Close stdin when done with it
    op item create --category=login </dev/null
    ```

    or more simply:

    ```

    !/bin/bash

    op item create --category=login </dev/null
    ```

  • Former Member's avatar
    Former Member

    Ah this can even easier be reproduced:

    this works:


    op item create --category=login

    this does NOT work:


    echo 'op item create --category=login' | bash

  • Former Member's avatar
    Former Member

    I can confirm on version 2.24.0 on OSX

    when I call on my command line


    op item create --category=login --vault=adrastea \
    --generate-password=64,letters,digits --title=postgres/nfcbox-preview

    => item will be created successfully

    when I call the same command programmatically from within python I get


    File "/Users/REDACTED/.pyenv/versions/3.10.6/lib/python3.10/site-packages/exec_utils/exec_utils.py", line 49, in wait
    raise ExecStrictError("error while executing %s,\nstdout: %s\nstderr: %s\n" % (
    exec_utils.exec_strict_error.ExecStrictError: error while executing ['op', 'item', 'create', '--category=login', '--vault=adrastea', '--generate-password=64,letters,digits', '--title=postgres/nfcbox-preview'],
    stdout:
    stderr: [ERROR] 2023/12/16 13:59:02 invalid JSON in piped input

    I assume you find no PTY and assume STDIN mode.