Skip to content

Instantly share code, notes, and snippets.

@Tatuck
Last active February 14, 2021 20:33
Show Gist options
  • Select an option

  • Save Tatuck/078c6cccdbbdbeaab16a027cd0c5c591 to your computer and use it in GitHub Desktop.

Select an option

Save Tatuck/078c6cccdbbdbeaab16a027cd0c5c591 to your computer and use it in GitHub Desktop.
Swap the keys of your json file with the values.
# Coded by Tatuck :D
# USAGE: python keys2value.py yourJSON.json yourJSONOUT.json
import json
import sys
jsonFile = open(sys.argv[1],"r")
jsonLoad = json.loads(jsonFile.read())
jsonInverted = {value:key for key, value in jsonLoad.items()}
open(sys.argv[2],"w").write(str(jsonInverted).replace("'",'"').replace(",",",\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment