Skip to content

Instantly share code, notes, and snippets.

@Algo-ryth-mix
Created May 12, 2022 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Algo-ryth-mix/c0a462cb983039912326580bcddd7085 to your computer and use it in GitHub Desktop.
Save Algo-ryth-mix/c0a462cb983039912326580bcddd7085 to your computer and use it in GitHub Desktop.
out of 2 json files make one
import argh
import json
import io
## very simple json patcher
## make sure to pip install argh
@argh.arg('basefile',help='path to the file you want to patch')
@argh.arg('patchfile',help='path to the file you want to patch BASEFILE with')
def main(basefile: str, patchfile: str):
with io.open(basefile,'r',encoding='utf-8') as basef:
base = json.loads(basef.read())
with io.open(patchfile,'r', encoding='utf-8') as patchf:
patch = json.loads(patchf.read())
patched = { **base , **patch }
with io.open(basefile,'w',encoding='utf-8') as patchedf:
patchedf.write(json.dumps(patched))
if __name__ == "__main__":
argh.dispatch_command(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment