I'm reading the output of op item get
(v2.6.0) and adding a brand new field to an existing section using jq
. It looks like this:
op item get "top-secret" | jq '.fields + [{ id: "my-new-field", type: "STRING", purpose: "", label: "my-new-field", value: "very secret", }]' | op item edit "top-secret"
This runs fine, a new version is generated but my-new-field
is not present in the 1password item. Changing values that are already present in the item works fine, just adding new ones silently fails. Anyone knows if this is the expected behavior?
I've verified the resulting json by creating with it a new item, but would like to avoid deleting an existing one to keep versions linked. I've also made a gnarly jq filter to turn JSON into shell arguments for op item edit
, but it honestly feels like a horrible hack I'd rather not maintain.
Would appreciate any guidance!
1Password Version: 8.8.0
Extension Version: Not Provided
OS Version: macOS 12.4
Browser:_ Not Provided
Comments
Team Member
Hi @unrob! The main impediment here is that though we support piped input for creating an item, we do not currently support piped input for editing one. This means that the above
op item edit "top-secret"
will not see the provided json at all and when it executes it will just edit the item "in place", replacing it with itself and only incrementing the version. May I suggest that you use field assignments (shell arguments) for this task:Add a new custom field to an item's section:
(extracted from the docs:
op item edit --help
)Is there any reason why the above solution is not desirable in your case?
Best,
Andi
Thanks for the suggestion @andi.t_1P . While that does work and I can turn a JSON document into that format, it's less than desirable to use yet another format for structured data when JSON already works just fine. Working with more than one field through scripting is very cumbersome, as one needs not only to format the data in those url-encoded-ish key value pairs, but also find a way to properly read potentially multi-line values in order to feed them into
op item edit
programatically.All doable, of course, but terribly annoying in my opinion; here's an example of how I went about it:
compare that to
Latter is more desirable in my opinion, and would love to see straight-from-json updating in
op
at some point in the future. At the very least, I'd expect invokingop item edit
without any key-value pairs should result in an error or warning, instead of it increasing the version.