Metadata-Version: 2.1
Name: jsontp
Version: 1.0.3
Summary: JSON Tree Parser
Home-page: https://pypi.org/project/jsontp
Author: Nodiru Gaji
Author-email: c0d3r.nodiru.gaji@gmail.com
License: License :: OSI Approved :: MIT License
Download-URL: https://github.com/ames0k0/jsontp
Platform: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.10
Description-Content-Type: text/markdown
License-File: LICENSE

Script to generate a json `tree` for `key` and dumping the `value` of the `key` by `tree`
```json
{"a": 1, "b": 2, "d": {"c": 3}}		# 'root -> d -> c'
{"a": 1, "b": 2, "d": [{"c": 3}]}	# 'root -> d -> [0] -> c'
```

#### Start
```bash
pip install jsontp
```

#### Example (API)
```python3
from jsontp import PageDataTree
from jsontp.utils import FileIO
from jsontp.config import Key

input_filepath = 'ranker_writer-ignore_me.json'
output_filepath = 'ranker_writer_user_content-ignore_me.json'

file_io = FileIO(input_filepath)
file_data = file_io.load()

pdt = PageDataTree(file_data)
pdt_tree = pdt.tree_by_key(key='user', result_to=Key.SAVE)

user_data = pdt.data_by_tree(next(pdt_tree))
file_io.dump(user_data, output_filepath)
```

#### Example (CLI)
```bash
# Search for `key` (-k), filter by `key` (-fk)
python -m jsontp -i <input_filepath> -k id -fk user

# Search for `key` (-k), filter by `key` (-fk), print the value for `tree`
python -m jsontp -i <input_filepath> -k id -fk user -o '*'

# Print the value for `tree` (NOTE: `-o <output_filepath>` - to dump a value)
python -m jsontp -i <input_filepath> -t 'root -> props -> ... -> user' -o '*'
```

#### Dependencies
```bash
pip -V		# 22.1.1
python -V	# 3.10.5
pytest -V	# 6.2.5
```

#### Script structure
```
# tree -I '__pycache__|env|build|jsontp.egg-info'
.
├── jsontp
│   ├── __init__.py
│   ├── __main__.py
│   ├── config.py
│   ├── utils.py
│   └── run.py
├── tests
│   ├── __init__.py
│   └── test_page_data_tree.py
├── data
│   ├── ranker_writer-ignore_me.json
│   └── ranker_writer_user_content-ignore_me.json
├── setup.py
├── LICENSE
├── README.md
├── UPDATES.txt
└── CONTRIBUTORS.md
```

#### TODO
- [x] nested json
- [x] json in the list
- [x] check for multiple keys
	- [x] return multiple keys (iterable result)
	- [ ] unique multiple keys (not every single item in the list)
- [ ] check for keys by value
- [x] access to the data in the list
	- [x] add and get the index from `tree`
- [ ] handle errors on searching for a non string key
- [x] fix errors on reading and writing to the json file without filename
	- [x] no need to test for writing
	- [x] raising an error `FileNotFoundError` for not valid input filepath

#### API
- [ ] Flags

#### CLI
- [x] Input
	- [x] json file
- [ ] Key
	- [x] search: `str`
	- [x] filter `tree` by must have `key` (-fk)
		- [ ] multiple (-fk)
	- [x] filter `tree` by must have `value` (-fv)
		- [ ] multiple (-fv)
	- [x] result (config.py[Key]): `print`, `return`
- [x] Limit
	- [x] `print`
	- [x] `return`
- [ ] Output
	- [x] dump a `value` to the file (`-o <output_filepath>`)
	- [ ] append to the dump file
	- [x] `print`: '\*'

Coding process: https://youtu.be/DkBAIKMN7x0

#### License
MIT
<br />
Copyright (c) 2022 srcown://ames0k0


