Opinionated JSON to CSV converter
Project description
Introduction
An opinionated JSON to CSV/XLSX converter which tries to make a useful relational output for data analysis.
It aims to be fast and memory efficient.
Install
pip install flatterer
Flatterer requires Python 3.6 or greater. It is written as a python extension in Rust but has binaries (wheels) for linux (x64), macos (x64 and universal) and windows (x64, x86). On other platforms a rust toolchain will need to be installed.
Example JSON
Say you have a JSON data like this named games.json
:
[
{
"id": 1,
"title": "A Game",
"releaseDate": "2015-01-01",
"platforms": [
{"name":"Xbox"},
{"name":"Playstation"}
],
"rating": {
"code": "E",
"name": "Everyone"
}
},
{
"id": 2,
"title": "B Game",
"releaseDate": "2016-01-01",
"platforms": [
{"name":"PC"}
],
"rating": {
"code": "E",
"name": "Everyone"
}
}
]
Running Flatterer
Run the above file with flatterer.
flatterer games.json games_dir
Output Files
By running the above you will get the following files:
tree games_dir
games_dir/
├── csv
│ ├── games.csv
│ └── platforms.csv
├── datapackage.json
├── fields.csv
└── ...
Main Table
games.csv
contains:
_link | _link_games | id | rating_code | rating_name | releaseDate | title |
---|---|---|---|---|---|---|
1 | 1 | 1 | E | Everyone | 2015-01-01 | A Game |
2 | 2 | 2 | E | Everyone | 2016-01-01 | B Game |
Special column _link
is generated. _link
is the primary key there unique per game.
Also the rating
sub-object is promoted to this table it has a one-to-one relationship with games
.
Sub-object properties are separated by '_'.
One To Many Table
platforms
is an array so is a one-to-many with games therefore needs its own table:
platforms.csv
contains:
_link | _link_games | name |
---|---|---|
1.platforms.0 | 1 | Xbox |
1.platforms.1 | 1 | Playstation |
2.platforms.0 | 2 | PC |
Link Fields
_link
is the primary key for the platforms
table too. Every table except games
table, contains a _link_games
field to easily join to the main games
table.
If there was a sub-array of platforms
then that would have _link
, _link_games
and _link_platforms
fields.
To generalize this the _link__<table_name>
fields joins to the _link
field of <table_name>
i.e the _link__<table_name>
are the foreign keys refrencing <table_name>._link
.
Fields CSV
fields.csv
contains some metadata about the output tables:
table_name | field_name | field_type | count | field_title |
---|---|---|---|---|
platforms | _link | text | 3 | _link |
platforms | _link_games | text | 3 | _link_games |
platforms | name | text | 3 | name |
games | _link | text | 2 | _link |
games | id | number | 2 | id |
games | rating_code | text | 2 | rating_code |
games | rating_name | text | 2 | rating_name |
games | releaseDate | date | 2 | releaseDate |
games | title | text | 2 | title |
The field_type
column contains a type guess useful for inserting into a database. The field_title
is the column heading in the CSV file or XLSX tab, which is initally the same as the field_name.
After editing this file then you can rerun the transform:
flatterer games.json new_games_dir -f myfields.csv --only-fields
This can be useful for renameing columns, rearranging the field order or if you want to remove some fields the --only-fields
flag will only include the fields in the edited file.
datapackage.json
contains metadata in the Tabular Datapackge Spec
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for flatterer-0.12.12-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f7f6e04e259620b48d2b18ed07eb0475fb735be9b6cbe948cfb36c4bf18ac8a |
|
MD5 | 11ecff7b39f64f05d44010622b98e082 |
|
BLAKE2b-256 | b6b0c8aeee6c7f9e717c27216c5e70fa4cd77911a5c38ba5346bea71003bf80d |
Hashes for flatterer-0.12.12-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a119209c8aa41e4b8970216b31bec01c2afc6699de2c73ab6c090d8211984ec |
|
MD5 | 45389d509dd9012d5b62e3634082b62f |
|
BLAKE2b-256 | 6773d4b3a154cb31c8bbde936a531925785cb9388b82d84050322065342139ba |
Hashes for flatterer-0.12.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be3a9c40e6a6b84e3852521cbba5e5aae2fed3b0d0bf094a0d25c192f060a631 |
|
MD5 | 6d0d0bc8baf9818ecff8544596a5298e |
|
BLAKE2b-256 | 1b5b73fb46a2c2136340a615e7ed98bd5c8114d68da722beb1d21b51dc685fa3 |
Hashes for flatterer-0.12.12-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffad99c98e0646e8c0520777f0ee4792e2fc26fbbcd065cb8d338d18a2335c41 |
|
MD5 | ae66ab5819aa67932fd73c704d223bc3 |
|
BLAKE2b-256 | 89d8c44dfba0fcae6c79dbc8c33941fd3ff788fa6fd08be8d3cc70172b8b7728 |
Hashes for flatterer-0.12.12-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 060f5ab3cba0804d057e230809d6bdfe7e64fefdd84195e782ff2dbc2f4e1d13 |
|
MD5 | 827002b11b22d5b78e4419126b342ea3 |
|
BLAKE2b-256 | 857bba01b6fd4f0d725420b25278781ccc5dbc4da7078d3ea2b2a6fee84f4032 |
Hashes for flatterer-0.12.12-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bc476973a2ae197ea38f8c2992f371d66fc1f9b7c867b5aa780fa55892c41fd |
|
MD5 | cd8529ddd15f2be885aff7bfd9d2a15d |
|
BLAKE2b-256 | 5bb0e1eba817f6b3b7b5850279cfded99669c74692fadd2b5aa7bfa30774bcfe |
Hashes for flatterer-0.12.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ea03e36df13afaf9b86ecdddd36a475e2ce5795bc7c60c2fbce39902b72437d |
|
MD5 | 645ff3f8a0b38f469688f4279e031c5f |
|
BLAKE2b-256 | e67c360d8933d4a5cd8b4952b3d4caf4df7c643a56ab1b2eed79670b85c4becb |
Hashes for flatterer-0.12.12-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8eb8bc671334cd36bcaeed0bc32b3893da3dc38b9c1fa984a9a0c734cdb2da9 |
|
MD5 | e2eda44a1d9e06d5f72ce03436a0592b |
|
BLAKE2b-256 | 851c795446acdaca0c49cb93aaf631a6843ca3af1ddb624e32dfbdbb96c0dc8f |
Hashes for flatterer-0.12.12-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6850a1f8885255855d9d39fb7a349b90868447d3f05ec7e0abc40ab52c7fe2bb |
|
MD5 | c13455d9754bbb994d9dbec8142749e4 |
|
BLAKE2b-256 | 0c2f791a5c3b2d2dc12723d4db761f50f7976fd145ced918872ffdd2f3d5b9dc |
Hashes for flatterer-0.12.12-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3b41e1726ac488a9b190f4c052bbfaa91511ccbff9804dea09f4234e8b36ccc |
|
MD5 | ba2bfaf655c9192180bed29053909f6b |
|
BLAKE2b-256 | 2df9e025c1182fb58e4e2ba6337d3a0219e52c066cff7717389e95bd57376a8a |
Hashes for flatterer-0.12.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a4b3f40ad539c68bd7092b1b642649316f1a450d6ede7bdd08c243a33fd33b6 |
|
MD5 | b5b6fd64b44d2413c596efa1677d6985 |
|
BLAKE2b-256 | 3dc8138032b03a2ee31d354871c445249771d4bb400c4f5879e53b3fc02c65eb |
Hashes for flatterer-0.12.12-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f502ec99cb51e1df63d2fa47a42778189e7922da4aa25f57635ac255d9d012fd |
|
MD5 | 3a297ef9657b7a8432980ef6586aa807 |
|
BLAKE2b-256 | 16bdeb190bb39ce76e1520449348071196ac80adc977501236fde42a05064a9e |
Hashes for flatterer-0.12.12-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab8ed5ff400dc40d101b6b4d0d5719f2c4c209aaa72ec89f53f985ade8b00c20 |
|
MD5 | 721dd6304fab1151f2cfc43797ed6cbd |
|
BLAKE2b-256 | 33e53c9d6ac387d13687876c3121dc8634de185453055aeeed97bd38e1dd5d36 |
Hashes for flatterer-0.12.12-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5b9f132c15d793174c3b13c8a545bddd0df68a678eef719c5697ca13a75ffc5 |
|
MD5 | 76da446d6c448832b64efb2b05286302 |
|
BLAKE2b-256 | 984a4295960823a9c4ab8d5c59f909f57c56cb891796dddfd24b6e0a4f08296a |
Hashes for flatterer-0.12.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b4200ae018e9e6223bf776a4914d62d02d0043a3b9835e93c28734feef72b34 |
|
MD5 | c5c29ff8675231b49c5d751efbddf67e |
|
BLAKE2b-256 | e67d8a5954a2ef3f8fbeb2c0eb68fa5e6fba22036920b3b70ae8b1885a43d648 |
Hashes for flatterer-0.12.12-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5253fc4a64a869070265120d944b3f42ae81b7f8cb483990f1f7a904c0d7cd94 |
|
MD5 | cade79f991de095d722a2911dc0cbff9 |
|
BLAKE2b-256 | 89707f1adaf8b58a7bf3750cf08f00627ca20d64d364b834ae6d8aef45679eca |
Hashes for flatterer-0.12.12-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00289d027d9ae34ac91bc7f3fb7f98b0a3a2a06e287cc4d35e7122d05286cd0c |
|
MD5 | 11ab027a11b4b0a30ccf42c03d852c73 |
|
BLAKE2b-256 | a3b851a7761c4d16b0b68878afa62871d7328ef7386295b5fcbbe7d58b38e9c1 |