Skip to content

Instantly share code, notes, and snippets.

@404mike
Created April 28, 2022 15:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save 404mike/ada00c6fc2a6caca31ed589be18fb247 to your computer and use it in GitHub Desktop.
import json
import os
from os.path import exists
def loopJsonFiles():
directory = os.fsencode('data')
for file in os.listdir(directory):
filename = os.fsdecode(file)
if filename.endswith(".json"):
updateJsonFile(filename)
def updateJsonFile(file):
path = "data/"+file
newPath = "complete/"+file
file_exists = exists(newPath)
if file_exists:
return
newData = []
with open(path) as json_file:
data = json.load(json_file)
for v in data:
id = v[0]
newId = id + '-ART45'
v[0] = newId
newData.append(v)
with open(newPath, 'w') as outfile:
outfile.write(json.dumps(newData))
if __name__ == '__main__':
loopJsonFiles()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment