Skip to content

Instantly share code, notes, and snippets.

@jalbertbowden
Forked from stp-ip/split_starred_json.py
Created June 29, 2018 04:31
Show Gist options
  • Save jalbertbowden/c0d1373a2bd23bd960a4c1110347695b to your computer and use it in GitHub Desktop.
Save jalbertbowden/c0d1373a2bd23bd960a4c1110347695b to your computer and use it in GitHub Desktop.
Python script to split starred.json into smaller junks to make them usable for alternatives. Sometimes trying to import starred.json files with more than 50mb or even less fail. -> split it and it should work.
# run script within a directory where your exported starred.json file is available
import json
from copy import deepcopy
json_data = open('starred.json')
data = json.load(json_data)
default = deepcopy(data)
default['items'] = []
l = len(data['items'])
ran = range(l)
steps = ran[1000::1000]
data_split = deepcopy(default)
count = 0
for i in ran:
data_split['items'].append(data['items'][i])
if i in steps or i == l-1:
name = 'starred_split_' + str(count) + '.json'
with open(name, 'w') as outfile:
json.dump(data_split, outfile)
data_split = deepcopy(default)
count = count + 1
print 'now you can import your splitted files into your new reader. One by one.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment