Possible to edit existing item with updated JSON?

zcutlip
zcutlip
Community Member

Maybe this is obvious and I'm overthinking it, but is it possible to round-trip the JSON returned by op get item?

I'd like to ingest that JSON, make several changes to the "details" dictionary, then provide that updated JSON (or the details dictionary within) as input to op in order to apply those changes.

Thanks,
Zach


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Sync Type: Not Provided

Comments

  • ag_yaron
    ag_yaron
    1Password Alumni

    Hey @zcutlip ,

    You can definitely build a script to do that.
    Using the op get item --format JSON command, you can output the details of an item (or specific fields of an item by your choosing) as shown here: https://support.1password.com/command-line-reference/#get-item

    Then, return the data in the same format after you edit it using the op edit item command, as shown here: https://support.1password.com/command-line-reference/#edit-item

    As long as you address the fields with the same JSON short name, things should work.
    Does this help?

  • zcutlip
    zcutlip
    Community Member

    Then, return the data in the same format after you edit it using the op edit item command, as shown here: https://support.1password.com/command-line-reference/#edit-item

    That does help a bit, but my main reason for wanting to feed modified JSON into an edit request is it allows changes that I don't think are possible via op edit item

    So for example: I'm adding SSH key passphrases to a Server item.
    Things I can do:

    • Create the server item from a json template with a custom "SSH KEYS" section
    • Have the custom section pre-populated with fields for each SSH key I want to set a password for

    Things I don't think I can do via the CLI:

    • Add the SSH KEYS (or any other) section after the fact
    • Add a new entry to the SSH KEYS section after the fact

    So it appears op edit item is limited to changing the values of existing fields, but there's no way to add new sections or fields...I think?

  • ag_yaron
    ag_yaron
    1Password Alumni

    Hey @zcutlip ,
    You are correct.

    However, it might be possible to do what you are asking with the op create item command, which will create a new item that you can feed that JSON to, after which you'll have to delete the original item if you want to avoid duplicates.

  • zcutlip
    zcutlip
    Community Member

    Okay, thanks for the clarification, @ag_yaron.

    Deleting/creating a new item is a bit heavyweight, but I think it should work for my use cases.

    Cheers,
    Zach

  • ag_yaron
    ag_yaron
    1Password Alumni

    I do hope you'll find it useful for now. We do plan on improving things so stay tuned :)

This discussion has been closed.