It’s Cybersecurity Awareness Month! Join our interactive training session, or learn about security and AI from 1Password experts.
Forum Discussion
adrianbj
5 years agoNew Contributor
anyone have examples of editing existing Vault entries from CLI?
I have several vaults within our company's division where we would like to add more entries for all.
I am looking for a path that I can follow to automate this.
I understand the limitation, but a...
Former Member
5 years agoHello adrianbj,
It sounds like you are trying to add in these new fields into one of the sections and that you're running into difficulty when a Login item has multiple sections.
You have a few different options to be able to add these new fields programmatically using jq.
- Add the new fields into the first section of the Login item,
- Add the new fields into the last section of the Login item,
- Create a new section that only contains your new fields.
Personally, I feel like Option 3 is the best aesthetically for the user, so I'll show you how to use jq to achieve that first.
Option 3: Create a new section that only contains your new fields
The += operator in jq allows you to merge one array into another array, like so:
jq '.sections += [{"title": "Section added by administrator", "fields": [{"k": "string", "t": "Purpose of the credential", "v": "enter text"}]}]' details.json
You'll note that the second half of the += operator is an array that contains an entire section object.
And here's a screenshot of how that will appear in 1Password.
We've created a brand new section called Section added by administrator that contains the one field we added in the array.
Option 2: Add the new fields into the last section of the Login item
If your goal is to combine these fields into an already-existing section, then here are those steps.
Similar to above, we are using the += operator to merge two arrays together. The source array is going to be the final section’s fields. In this case, we are merging in an array of field objects, rather than an array that contains a section object. Note that negative indices are allowed, with -1 referring to the last element, -2 referring to the next to last element, and so on.
jq '.sections[-1].fields += [{"k": "string", "t": "Purpose of the credential", "v": "enter text"}]'
And here's what that looks like:
You can see that our new Purpose of the credential field has been added into the Already existing section section.
I hope that this helps. Please feel free to write back with any additional questions you may have.