https://github.com/zapier/jsonmask
Implements Google Partial Response dictionary pruning in Python
https://github.com/zapier/jsonmask
Last synced: about 1 year ago
JSON representation
Implements Google Partial Response dictionary pruning in Python
- Host: GitHub
- URL: https://github.com/zapier/jsonmask
- Owner: zapier
- License: mit
- Created: 2018-08-24T19:00:08.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-08-20T10:06:39.000Z (almost 4 years ago)
- Last Synced: 2025-04-12T03:38:37.337Z (about 1 year ago)
- Language: Python
- Size: 85.9 KB
- Stars: 14
- Watchers: 6
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://travis-ci.org/zapier/jsonmask) [](https://coveralls.io/r/zapier/jsonmask) [](https://pypi.org/project/jsonmask)
# Overview
Implements [Google Partial Response](https://developers.google.com/discovery/v1/performance#partial-response) / [`json-mask`](https://github.com/nemtsov/json-mask) in Python.
## Requirements
* Python 2.7
* Python 3.6+
## Installation
Install jsonmask with pip:
```sh
$ pip install jsonmask
```
or directly from the source code:
```sh
$ git clone https://github.com/zapier/jsonmask.git
$ cd jsonmask
$ python setup.py install
```
# Usage
After installation, the package can imported:
```sh
$ python
>>> import jsonmask
>>> jsonmask.__version__
```
To prune dictionaries:
```py
>>> import jsonmask
>>> mask = jsonmask.parse_fields('a,b(c,d)')
>>> jsonmask.apply_json_mask(
{
'a': {
'nested_within_a': True,
},
'b' {
'c': True,
'd': {'Will get included?': 'Yes'},
'e': 'Tough luck here',
},
'c': 'Definitely hopeless',
},
mask,
)
{
'a': {
'nested_within_a': True,
},
'b' {
'c': True,
'd': {'Will get included?': 'Yes'},
},
}
```