11'''
22Name: remove-json-keys.py
3- Version: 2026.2.10.9
3+ Version: 2026.2.10.10
44Author: Adam Lui
5- Description: Remove key/value pairs from json_folder /**.json
5+ Description: Remove key/value pairs from json_dir /**.json
66Homepage: https://github.com/adamlui/python-utils
77Support: https://github.com/adamlui/python-utils/issues
88Sponsor: https://github.com/sponsors/adamlui
1717parser .add_argument ('--remove-keys' , type = str , help = 'Keys to remove' )
1818parser .add_argument ('--json-dir' , type = str , help = 'Name of folder containing JSON files' )
1919args = parser .parse_args ()
20- json_folder = args .json_folder or '_locales'
20+ json_dir = args .json_dir or '_locales'
2121
2222# UI initializations
2323try :
@@ -41,24 +41,24 @@ def parse_csv_str(str) : return [lang.strip() for lang in str.split(',') if lang
4141 remove_keys .append (key )
4242
4343# Determine closest JSON dir
44- print_trunc (f'Searching for { json_folder } ...' )
44+ print_trunc (f'Searching for { json_dir } ...' )
4545script_dir = os .path .abspath (os .path .dirname (__file__ ))
4646for root , dirs , files in os .walk (script_dir ): # search script dir recursively
47- if json_folder in dirs :
48- json_dir = os .path .join (root , json_folder ) ; break
47+ if json_dir in dirs :
48+ json_dir = os .path .join (root , json_dir ) ; break
4949else : # search script parent dirs recursively
5050 parent_dir = os .path .dirname (script_dir )
5151 while parent_dir and parent_dir != script_dir :
5252 for root , dirs , files in os .walk (parent_dir ):
53- if json_folder in dirs :
54- json_dir = os .path .join (root , json_folder ) ; break
53+ if json_dir in dirs :
54+ json_dir = os .path .join (root , json_dir ) ; break
5555 if json_dir : break
5656 parent_dir = os .path .dirname (parent_dir )
5757 else : json_dir = None
5858
5959# Print result
6060if json_dir : print_trunc (f'JSON directory found!\n \n >> { json_dir } \n ' )
61- else : print_trunc (f'Unable to locate a { json_folder } directory.' ) ; exit ()
61+ else : print_trunc (f'Unable to locate a { json_dir } directory.' ) ; exit ()
6262
6363# Process JSON files and remove specified keys
6464keys_removed , keys_skipped , processed_count = [], [], 0
0 commit comments