Skip to content

Instantly share code, notes, and snippets.

@kandhan-kuhan-t
Created October 14, 2020 13:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kandhan-kuhan-t/7a74cb0f8d3de404cce7f97a6e8a13d6 to your computer and use it in GitHub Desktop.
Save kandhan-kuhan-t/7a74cb0f8d3de404cce7f97a6e8a13d6 to your computer and use it in GitHub Desktop.
This converts the json file (you'll have to extract 'export.data' file from '*.1pux' file) exported from 1password (linux app) to .csv
#! /usr/bin/python3
import json
import csv
# extract export.data from .1pux file using archive manager
# extract.data is a json file
json_file_path = './export.data'
# output file path
csv_to_export_name = './1password-export.csv'
fields = ['url', 'name', 'username', 'password']
def get_rows():
records = []
with open(json_file_path, 'r') as json_file:
j = json.load(json_file)
for account in j['accounts']:
for vault in account['vaults']:
for item in vault['items']:
username = ''
password = ''
name = ''
url = ''
loginFields = item['item']['details']['loginFields']
for field in loginFields:
if field['fieldType'] == 'T':
username = field['value']
if field['fieldType'] == 'P':
password = field['value']
name = item['item']['overview']['title']
url = item['item']['overview']['url']
if username == '' and password == '':
...
else:
records.append([url, name, username, password])
return records
def transform():
with open(csv_to_export_name, 'w') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(fields)
for row in get_rows():
csvwriter.writerow(row)
if __name__ == '__main__':
transform()
@yarmoliq
Copy link

it seems like you should remove ['item']. at least that was needed to convert my file i generated today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment