flatten-single-item-arrays
Given a JSON list of objects, flatten any keys which always contain single item arrays to just a single value
Installation
Install this tool using pip:
$ pip install flatten-single-item-arrays
Usage
This will output the rewritten JSON:
$ flatten-single-item-arrays input.json
You can save it to a file like this:
$ flatten-single-item-arrays input.json > output.json
Use --debug to see extra debugging information displayed on standard error:
$ flatten-single-item-arrays input.json --debug > output.json
Item count: 2
count_of_single_item_lists
{
"foo": 2
}
count_of_present_keys
{
"foo": 2,
"bar": 2
}
keys_to_reformat:
- foo
What this does
This tool accepts the path to a JSON file and outputs a modified version of that JSON file where any keys that are always single item lists are rewritten to a single value.
For example, the following input:
[
{
"foo": [
"bar"
],
"bar": 5
},
{
"foo": [
"baz"
],
"bar": 6
}
]
Will be transformed to this:
[
{
"foo": "bar",
"bar": 5
},
{
"foo": "baz",
"bar": 6
}
]
I built this to help work with data from the Airtable API, which often contains this single-item-list pattern.
Development
To contribute to this tool, first checkout the code. Then create a new virtual environment:
cd flatten-single-item-arrays
python -mvenv venv
source venv/bin/activate
Or if you are using pipenv:
pipenv shell
Now install the dependencies and tests:
pip install -e '.[test]'
To run the tests:
pytest
Metadata
Release files for flatten-single-item-arrays 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flatten-single-item-arrays-0.1.tar.gz | 3.2 kB | Without provenance | Details for flatten-single-item-arrays-0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flatten_single_item_arrays-0.1-py3-none-any.whl | Python 3 | none | any | Details for flatten_single_item_arrays-0.1-py3-none-any.whl |
Total release size: 11.0 kB
Release files / flatten-single-item-arrays-0.1.tar.gz
| Download URL | flatten-single-item-arrays-0.1.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88f44be0d158dbcb63b978dba84d8845ca03900ab869b44d36bf5884255b8827
|
|
BLAKE2b-256 checksum How to use checksums |
315bcb08fccb86a4114485b3940e37466d858e210f2e64be33d8041aabf9efce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1
|
Release files / flatten_single_item_arrays-0.1-py3-none-any.whl
| Download URL | flatten_single_item_arrays-0.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fab33e3517dc13e4468fca851dbc1f758cd537355c7d99dbd37c376824544499
|
|
BLAKE2b-256 checksum How to use checksums |
65f9ffb26b5a348204f5247fe65e8764cda1e578bf72b22edcb9b3e92abfc53d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1
|
Security for flatten-single-item-arrays 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.