Skip to main content

Opinionated JSON to CSV converter

Project description

Full Documentation

Introduction

An opinionated JSON to CSV/XLSX/SQLITE/PARQUET converter which tries to make a useful relational output for data analysis.

Web playgroud of CSV/XLSX conversions

Rationale

When receiving a JSON file where the structure is deeply nested or not well specified, it is hard to determine what the data contains. Also, even after knowing the JSON structure, it requires a lot of time to work out how to flatten the JSON into a relational structure to do data analysis on and to be part of a data pipeline.

Flatterer aims to be the first tool to go to when faced with the above problem. It may not be the tool that you end up using to flatten the JSON in your data pipeline, as hand written flattening may be required, but it could be. It has many benefits over most hand written approaches:

  • It is fast, written in rust but with python bindings for ease of use. It can be 10x faster than hand written python flattening.
  • Memory efficient. Uses a custom streaming JSON parser to mean that long list of objects nested with the JSON will be streamed, so not much data needs to be loaded into memory at once.
  • Fast memory efficient output to CSV/XLSX/SQLITE/PARQUET
  • Uses best practice that has been learnt from flattening JSON countless times, such as generating keys to link one-to-many tables to their parents.

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 Data Package Spec

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flatterer-0.24.1.tar.gz (8.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

flatterer-0.24.1-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (14.2 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

flatterer-0.24.1-cp315-cp315-manylinux_2_28_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.15manylinux: glibc 2.28+ x86-64

flatterer-0.24.1-cp314-cp314-win_amd64.whl (13.4 MB view details)

Uploaded CPython 3.14Windows x86-64

flatterer-0.24.1-cp314-cp314-win32.whl (12.2 MB view details)

Uploaded CPython 3.14Windows x86

flatterer-0.24.1-cp314-cp314-manylinux_2_28_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

flatterer-0.24.1-cp314-cp314-macosx_11_0_arm64.whl (12.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

flatterer-0.24.1-cp313-cp313-win_amd64.whl (13.4 MB view details)

Uploaded CPython 3.13Windows x86-64

flatterer-0.24.1-cp313-cp313-manylinux_2_28_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

flatterer-0.24.1-cp313-cp313-macosx_11_0_arm64.whl (12.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

flatterer-0.24.1-cp312-cp312-win_amd64.whl (13.4 MB view details)

Uploaded CPython 3.12Windows x86-64

flatterer-0.24.1-cp312-cp312-manylinux_2_28_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

flatterer-0.24.1-cp312-cp312-macosx_11_0_arm64.whl (12.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

flatterer-0.24.1-cp311-cp311-win_amd64.whl (13.4 MB view details)

Uploaded CPython 3.11Windows x86-64

flatterer-0.24.1-cp311-cp311-manylinux_2_28_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

flatterer-0.24.1-cp311-cp311-macosx_11_0_arm64.whl (12.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

flatterer-0.24.1-cp310-cp310-win_amd64.whl (13.4 MB view details)

Uploaded CPython 3.10Windows x86-64

flatterer-0.24.1-cp310-cp310-manylinux_2_28_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

flatterer-0.24.1-cp39-cp39-manylinux_2_28_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

File details

Details for the file flatterer-0.24.1.tar.gz.

File metadata

  • Download URL: flatterer-0.24.1.tar.gz
  • Upload date:
  • Size: 8.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for flatterer-0.24.1.tar.gz
Algorithm Hash digest
SHA256 4d3b466f2ec8b36b68b860ba7611d29f6c305feb6e6d20e35e7902a78ac3c813
MD5 80c03f3b79fbe1060d9688d605094bc5
BLAKE2b-256 e9ec17904cb653143b5cba29990aa7522c7c95c1c81a8b3aafc33f41bdcdbd70

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6e31c31dc016a83f3296a858678f49ba400542743be0dab1d11cda641ae19a9a
MD5 64136c99278b43538d9b50a1d5834908
BLAKE2b-256 b645180a5feea4079aec60f1f12fd437506f6c8f0f423317acf29c46839bdc21

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp315-cp315-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp315-cp315-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d8c74a05d72a06e621a706bad56685f98084fdc307fab95c05adaf81b3cf2ea
MD5 e328f386065b326cb82482c17198a8ee
BLAKE2b-256 8e1b776e228e22c2fccc4f654235ad6248d2c258f2d21b130aeef0c6d3914bed

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c04c2c56af340b77ff2e8dc0fe89746fc7473729458a7f6bad81d4c0d23984e5
MD5 075cdfd20c9ee27e3f20c84796410b71
BLAKE2b-256 052477cda23b0b22cf9756e8df943fde3bf947f4c8e3a079c89417e5fec60653

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp314-cp314-win32.whl.

File metadata

  • Download URL: flatterer-0.24.1-cp314-cp314-win32.whl
  • Upload date:
  • Size: 12.2 MB
  • Tags: CPython 3.14, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for flatterer-0.24.1-cp314-cp314-win32.whl
Algorithm Hash digest
SHA256 5e8cbf25712c0768ac710cf801b9172e56b2f0eea6c7cbcfb6a727873b69fe21
MD5 f30a42974e1f3ec386e7424956ebeda6
BLAKE2b-256 0d659cde1a75d64cb5ddd8a19ec8823c652c37b84b9ad10a2658e41044c7f384

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c5db41c1ec112d15d45a863a704899f66f673e9d1300ab12b29cb697f7640db5
MD5 31702232bf644a61622309e7ff8bc7ed
BLAKE2b-256 4208dfcde46f2c45ac4bce8c2949318ccda62bd5b013e9b799e4759bac2b888a

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9874457f343689340495a1fd7a818f0eb1cd1469a716ec531ae73c9affc4719d
MD5 2189470f94fd447afddb62286640ba19
BLAKE2b-256 3e9555bb4eaf91f69a0cdfad4b7aba23ccea15a5805edfa00441bb9e2d636e29

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 70253bd6af5e7b114e8fe519e613df52ef9b5485d9058d0851c7ac5836aa78ab
MD5 5889079ba64e023bc67e7d3032d22a82
BLAKE2b-256 003a5538ee3985c39b90e35f4c475ed0f07790443f3740c1fa474f3ee72409b0

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bb783a8a505a95bc9b3a377a477f6baf069a1c9e8c5b931b0441dc372f8d5cc8
MD5 a9fa5b78e8289955bf167a3dedda954b
BLAKE2b-256 c53ddace038cb56b2068c0dd60a5fbb7b384a310b24c284056ad43af564111c2

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5019837a0fa3fa7bec1451550746f9e2688c4559dff4408334d04d1770c16572
MD5 12f4f15e8b83e2861e93cb8dd12224c0
BLAKE2b-256 fe1735ac406b13749530d0b345511ceb72a6ec3da97df79d510fbf2af3761055

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6a324c703819113338ab43f6201f7f4109cece87dc9ac4a36acf480a80844054
MD5 c771c79ff93d6f34f52fba3fb4d586a8
BLAKE2b-256 35fc317c897c7a8adc0fc210a01db4349627f3cf473e3cc9c42b2f9e49705ee2

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 636afcb350d7b4423b0aefeaced11a300a0644aa9729c5d2b332591c94f1ccb9
MD5 f3cf0454dd9af64bbd3d914c5980cc55
BLAKE2b-256 39e0d739c6554f8a10e99b0788c6c748eff266a9ebbc4ef53319c3925fda48b9

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bdbd5bd63bd94ccc8422ba030517290658a0e3a482e9c25a2d6d3dddbf8a8d2d
MD5 c9f2b65d9e0222cd6fcc6d9d4e860469
BLAKE2b-256 23324c5876349e5c02c2654ea67ceab93c9f5b6f0d047c78a8e4151e9952221d

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c753837ba7dfeb5c4170ee3897e4448cfafbf469af17b78c786f4559b651918e
MD5 697d2975a100fc28e494644d73942bca
BLAKE2b-256 e68cd75b145068134be514053d5ff10e0cfeafa7ccfa3c0fe5b9d86bd8e98e85

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 751e26ba934aa3b363fe9bee9d406ac926205f9d3efe63372933a96f13e124dd
MD5 3271359bce62912d278fa5b078c7fb52
BLAKE2b-256 3775aee4581f738dc73113bc7b6faa79357be3911f72f11a8592bb7debefd99f

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 09ed383c51972988e8b07e74aac474a2937d4690e3d790f6b9639357a91da284
MD5 b05c3bd1b092065c3659bb427a81a072
BLAKE2b-256 9afcf916bda2f647d7a56e8c73c46297c20e5a159bd4ed142ca4a0fe88444f4d

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a622d121c0b952b682ade16c9cff5553a4648e3b819cd1d36c6efee01f4148c9
MD5 9cfc688b296fca39946689f1922fd96c
BLAKE2b-256 e85b941b936aa0e62210f0f5918035aff574f2c604d7d150cbfc07e4b1428cc0

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7582045f439c4a12a44154cad4c42bf7f46be9df845296b876e16c4ab7e3f90e
MD5 66207d48b13dfe32a483284233ced5ac
BLAKE2b-256 8d86038764fc1cc76d6e68246a31082c1291bf87b2d5bf1e3d7db6fc221c4424

See more details on using hashes here.

File details

Details for the file flatterer-0.24.1-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.24.1-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ae3c668b168b1ca11f9a665882fdd876931eb59fb4747fdcb2502c8b726cf147
MD5 e630b91ba9ab6a31a93f47b755c48f55
BLAKE2b-256 cfceea6753f8dac25c12e3a19587392ed4f366f6fae113b7962068cf3397de59

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page