Skip to content

sm-alejandro/json.py

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


json_helper.py

Bulk edit tools for json files in python
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Prerequisites
  3. Installation
  4. Usage
  5. License
  6. Contact

About The Project

(back to top)

Prerequisites

All code runs on python using following native libraries

  • pathlib
  • json
  • argparse (only for cli usage)
  • unittest for testing purposes

Installation

  • 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

(back to top)

Usage

PACKAGE USAGE

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):



CONSOLE USAGE (operations on example.json)

ADD

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"


DELETE

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"


REPLACE

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"

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Your Name - @zilmosat - [email protected]

Project Link: https://github.com/zilmosat/json_helper.py

(back to top)

About

Functions to bulk add/delete/modify json fields

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages