Bulk edit tools for json files in python
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
All code runs on python using following native libraries
- pathlib
- json
- argparse (only for cli usage)
- unittest for testing purposes
- Clone the repo
- Call the individual files via the command line (add_field.py, delete_field.py and replace_field.py)
- Use the functions directly in your code importing bulkjson.py
import bulkjson
bulkjson.add(data: dict, loc: str, key: str, val, rec: bool)
bulkjson.delete(data: dict, loc: str, key: str, rec: bool):
bulkjson.replace(data: dict, loc: str, key: dict, rec: bool):
Simple additions (adding to every key in the root of the document):
py ./add_field.py -data ./data/example.json -key "timestamp"
Recursive additions (adding to every possible dictionary)
py ./add_field.py -data ./data/example.json -key "custom" -rec
Add to specific key
py ./add_field.py -data ./data/example.json -key "direction" -loc "wind"
Simple deletions (deleting from every key in the root of the document):
py ./delete_field.py -data ./data/example.json -key "wind"
Recursive deletions (deleting from every possible dictionary)
py ./delete_field.py -data ./data/example.json -key "speed" -rec
Remove from certain key
py ./delete_field.py -data ./data/example.json -key "speed" -loc "wind"
Simple replacements (replacing from every key in the root of the document):
py ./replace_field.py -data ./data/example.json -key "{'measurement_2': 'measurement_4'}"
Recursive replacements (replacing from every possible dictionary)
py ./replace_field.py -data ./data/example.json -key {'wind': 'temperature'} -rec
Remove from certain key
py ./replace_field.py -data ./data/example.json -key {'speed': 'quantity'} -loc "rain"
Distributed under the MIT License. See LICENSE
for more information.
Your Name - @zilmosat - zilmosat@gmail.com
Project Link: https://github.com/zilmosat/json_helper.py