scripts.modify_json module
modify_json
This script allows the user to add or change a certain value to all json files included in a folder. This is done by taking a folder filled with json files, and creating a new folder at a target location filled with the new json files. The changes or not directly done to the original folder to ensure that we do not lose any data.
All the json files are converted and handled as dictionaries.
The script is run through the command line and has 4 parameters:
input_folder: The folder that contains the json files that you want to add or change values output_folder: The folder that the changed json files will appear variable_name: The name of the variable you want to introduce or change variable_value: The value of the variable tou want to introduce or change
E.g. if we want to introduce the new catch_rate and give it the value 125 to all files I will run python modify_json input_file output_file catch_rate 125 The new json files will be located at the output file
-GDMarkou
- scripts.modify_json.json_to_dict(json_file)[source]
Open a json file and loads it as a python dictionary
Parameters
json_file: file .json
Returns
json_dict: dict
- scripts.modify_json.modify_json(input_folder, output_folder, variable_name, variable_value)[source]
Add or change a certain value to all json files included in a folder
Parameters
- input_folder: String
location of the folder containing the json files
- output_folder: String
location of the folder we want to create the new json files
- variable_name: String
The name of the variable we want to create
- variable_value: Float
The value of the variable we want to create