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.25.0.tar.gz (8.1 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.25.0-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (14.9 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

flatterer-0.25.0-cp315-cp315t-manylinux_2_28_x86_64.whl (14.9 MB view details)

Uploaded CPython 3.15tmanylinux: glibc 2.28+ x86-64

flatterer-0.25.0-cp315-cp315-manylinux_2_28_x86_64.whl (14.9 MB view details)

Uploaded CPython 3.15manylinux: glibc 2.28+ x86-64

flatterer-0.25.0-cp314-cp314t-manylinux_2_28_x86_64.whl (14.9 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ x86-64

flatterer-0.25.0-cp314-cp314-win_amd64.whl (14.0 MB view details)

Uploaded CPython 3.14Windows x86-64

flatterer-0.25.0-cp314-cp314-win32.whl (12.6 MB view details)

Uploaded CPython 3.14Windows x86

flatterer-0.25.0-cp314-cp314-manylinux_2_28_x86_64.whl (14.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

flatterer-0.25.0-cp314-cp314-macosx_11_0_arm64.whl (13.2 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

flatterer-0.25.0-cp313-cp313-win_amd64.whl (14.0 MB view details)

Uploaded CPython 3.13Windows x86-64

flatterer-0.25.0-cp313-cp313-manylinux_2_28_x86_64.whl (14.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

flatterer-0.25.0-cp313-cp313-macosx_11_0_arm64.whl (13.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

flatterer-0.25.0-cp312-cp312-win_amd64.whl (14.0 MB view details)

Uploaded CPython 3.12Windows x86-64

flatterer-0.25.0-cp312-cp312-manylinux_2_28_x86_64.whl (14.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

flatterer-0.25.0-cp312-cp312-macosx_11_0_arm64.whl (13.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

flatterer-0.25.0-cp311-cp311-win_amd64.whl (14.0 MB view details)

Uploaded CPython 3.11Windows x86-64

flatterer-0.25.0-cp311-cp311-manylinux_2_28_x86_64.whl (14.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

flatterer-0.25.0-cp311-cp311-macosx_11_0_arm64.whl (13.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

flatterer-0.25.0-cp310-cp310-win_amd64.whl (14.0 MB view details)

Uploaded CPython 3.10Windows x86-64

flatterer-0.25.0-cp310-cp310-manylinux_2_28_x86_64.whl (14.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

flatterer-0.25.0-cp39-cp39-manylinux_2_28_x86_64.whl (14.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

File details

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

File metadata

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

File hashes

Hashes for flatterer-0.25.0.tar.gz
Algorithm Hash digest
SHA256 e0691fee36c4740fd0328b610d6ce761c6ae4f45314433582148f27bc22a8889
MD5 b7bf9915144301ef03c4e97c66e7e518
BLAKE2b-256 4124fc03395923c00ff5d1ee21b69b31ec03ccfe10b5fbb6e947100d350e8ee1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d6c4c8d3752bcc6f811e350de5a0f2d989035a93d9bc9f7ef07113134663c9f7
MD5 cbd2ec351ccb7b423082fc8ef5d75d53
BLAKE2b-256 86bc784365d205962b2a74597235bca93c8b759d5e8e88215ee03b7ce3306755

See more details on using hashes here.

File details

Details for the file flatterer-0.25.0-cp315-cp315t-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.25.0-cp315-cp315t-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a9af1209bce8125363fcb9db9b148a3a653f17c33d829cedb568845e44db9215
MD5 2a3dab74cdf2aa303cd6e83622cfbfe0
BLAKE2b-256 2408c47fac420cd5047525955e9b40836681b34a00f58a0c16eb1508d12ad303

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp315-cp315-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2de737778f93926d115063108db84221d0799240d1ba74d2258e4c0518ede4dc
MD5 178cb62e905e164148f335972301cb79
BLAKE2b-256 f4260a1435ff49ae5689134e1e6668e5512071bc9eefa727efab21f40c247ae6

See more details on using hashes here.

File details

Details for the file flatterer-0.25.0-cp314-cp314t-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.25.0-cp314-cp314t-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ad951b59fac65417b030833a247ddc35dac4c27909a903fb8b378aecc3d9b004
MD5 ee29ae40575b94de833c8a72a56ac5eb
BLAKE2b-256 ce26a3f627746f106c61cdbd7d76c580586ac36944f6c00b4c5196610326b3fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 a75808ff13a9791f181b9a06e4d1aefd53837366a74fe3df36dd59cf054ed271
MD5 2619ab75d9c0420fb6c3a29e5fef75c6
BLAKE2b-256 78b7d5afa8b90e49e09f1075b09759897a4fc306383e9d60494ba6e8cd6126d1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for flatterer-0.25.0-cp314-cp314-win32.whl
Algorithm Hash digest
SHA256 cf1d0fe9d38cf3aefc6b029dfb128f8c2ffe1f553c1443035a47ab0fec0815f9
MD5 3fdd9b21b0692419355917c7512e3fbe
BLAKE2b-256 767d2904e457db1180363c4bc125cffa8f6364dbd2e76956447ed9d60f9ca7e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c276ced987c3b3ef167545b32ee38bf756dc62f8911f07691c732ca05b129a52
MD5 870f2e074893c963a86f6fb5b3ab754a
BLAKE2b-256 b57553819108c7c99f930b3cc30dc41eb5430c122491f07e13a61bf615bf0e3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e7c8c239ec1e7358d15e6b5e2ded541cce66440dcc16f394690605d5f6ddede9
MD5 8852438f7571ecf5f71b7f5a75eb0fbd
BLAKE2b-256 47c0c5f1ff49464cda6fdc69e22d9dbfeb141249dc1b565ac3ab841b16b6a680

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 45319a22f5706d7c0896e03fefb2d2284b320e8c3c64b39f4ca956b59364a3ee
MD5 fd6e8c7b549a076f2024df0fd295c0b1
BLAKE2b-256 badab45b82473ed6d1c2c23260e25d133a9cc885c89b1e8f0107098981e64fd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0c571ed778e5896bc88d8b450f0b331579b5feb0e6c66f329178a1cd58370177
MD5 4b759567b4377f3b2e94105b3506efb7
BLAKE2b-256 1c1134b3cb0f4fedaf2da58f2559e4f783b8235bfb3de13e27961e337b6a9e21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 57c6acfb481cca2a08b5ab7266cebee9b33164ed75bb078e813e75215e177d6f
MD5 5698abb32d2ee9f34cebce016a017b0b
BLAKE2b-256 c15fe2a4693cdbe146d55f614ee83a53c7e678ee7304ebca844386776e1bfa62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7f743511c8e9483e03df93ab4ea00dd67e592f81c94c2d2e3f4d84ccc44a1bdb
MD5 9f7f636817b5d0fcf966994838ebc30e
BLAKE2b-256 f661e351a43bbb0b51f47cc8ec15e49d9233698e49a11a291de9152d34f359b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cf745b8a9d798950d65cb18dd7135c3d0d3595e30c67cfb53c85dfd4d1c84f66
MD5 f8187dbcb6194f5a94e83ab633106476
BLAKE2b-256 aaa3e3c2c7833e3367e7923abe6c67c117d7df2ba72e49d2a77861b3f322b864

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4d38e25d1efd43704702585976d3e8ffc9c518437bcbaf72a4e8ec55c5462ae
MD5 0592c5883830658fbca649f3b7b5cddb
BLAKE2b-256 a2703b2f8c409f3ca32593e7be271a9f69ed17e8f019958b9370c12200cbafdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 defb93ef50246617179dfdee983b4ff3278e9f9605c6b384e9fd960e0cdf182b
MD5 eea5e0c920ea606c5df857dff1d7cdc0
BLAKE2b-256 7488c259a9f74bf588b5628dd1d3229fc8046ecb62edcb626183e1df62312beb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 494a7ed1dc0072a5317909159bb8a4a490a9af27cb310e7e89c6915864217c21
MD5 7697df39a80766eb873d88201fac6a7c
BLAKE2b-256 05db37ce166ab32ec037a342e17479df8886922b18fdc0e887fd8e4218418a05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd588da673b8323ccb491c75cf3b19b91197a70d86a12ce8c108a111b4c5b82a
MD5 ddc1181d51669cf8a8c732563224fb84
BLAKE2b-256 8dc3339d804afc8ffc69ce658ec50a8fdcf13614c3c63201395b973c40e42c94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 eb734a3b0b4499a0d12fab808fdcee196a9abc2585afaa5e48d62d8615368f20
MD5 fd54ded18ac11aa5a1b21f92c1b57173
BLAKE2b-256 023bf003f106687e346fef1537f0433e3adf11e906fb890713ac9b4ca638661c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6efa82f83134b6bca6950605ac15d18950ce1eb6527bcbd71b29fc5a792ba0b1
MD5 a3870877b7d2bc5c30b836cb044dfbac
BLAKE2b-256 e12a091452c3599d87793ed2e6abee9c89bc2742187490ae401a3670b8e88950

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatterer-0.25.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 72cdde00cbc88df410907ecaf44619cb86df960bed1861c6dfdc1050bd2e089a
MD5 b1de20f18238f0d5f539d07e4b201f7e
BLAKE2b-256 590d00455d01b3056e6ca5c89a5740f2859c75bb389ec0a530df22c10e263f9b

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