Flatson
A tool to flatten JSON-like objects, allowing to configure via an annotated JSON schema
Free software: BSD license
Documentation: https://flatson.readthedocs.org.
Features
Flattens Python dictionaries using a JSON schema
Supports per-field configuration via the schema
Usage:
>>> from flatson import Flatson
>>> schema = {
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"},
"address": {
"type": "object",
"properties": {"city": {"type": "string"}, "street": {"type": "string"}}
},
"skills": {"type": "array", "items": {"type": "string"}}
}
}
>>> sample = {
"name": "Claudio", "age": 42,
"address": {"city": "Paris", "street": "Rue de Sevres"},
"skills": ["hacking", "soccer"]}
>>> f = Flatson(schema)
>>> f.fieldnames
['address.city', 'address.street', 'age', 'name', 'skills']
>>> f.flatten(sample)
['Paris', 'Rue de Sevres', 42, 'Claudio', '["hacking","soccer"]']
You can get a dict with the field names order preserved:
>>> f.flatten_dict(sample)
OrderedDict([('address.city', 'Paris'), ('address.street', 'Rue de Sevres'), ('age', 42), ('name', 'Claudio'), ('skills', '["hacking","soccer"]')])
You can also configure array serialization behavior through the schema (default JSON):
>>> schema = {
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"properties": {
"name": {"type": "string"},
"skills": {
"type": "array",
"items": {"type": "string"},
"flatson_serialize": {"method": "join_values"},
}
}
}
>>> f = Flatson(schema)
>>> f.flatten({"name": "Salazar", "skills": ["hacking", "socker", "partying"]})
['Salazar', 'hacking,socker,partying']
History
0.1.0 (2015-06-02)
First release on PyPI.
Metadata
Release files for flatson 0.1.0
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 |
|---|---|---|---|---|
| flatson-0.1.0.tar.gz | 15.6 kB | Without provenance | Details for flatson-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flatson-0.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for flatson-0.1.0-py2.py3-none-any.whl |
Total release size: 21.4 kB
Release files / flatson-0.1.0.tar.gz
| Download URL | flatson-0.1.0.tar.gz |
|---|---|
| Size | 15.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e63836d7b7f403ef56f43e62478bf322c77e9510a82a6c878e43c11b163cb8a
|
|
BLAKE2b-256 checksum How to use checksums |
2dad1448b5223740acbe699a2d9740c94cd95fbee69593b4d65a49663cfe7ce5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / flatson-0.1.0-py2.py3-none-any.whl
| Download URL | flatson-0.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
561d8401cff143e4977f02bc2812d890e88aec99c4651eac63da69af1ef07b45
|
|
BLAKE2b-256 checksum How to use checksums |
29655797c3cd3ab571c889817d28cb11c4c5ba739f7c1c0e46c9d710943bd87a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for flatson 0.1.0
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.