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.

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 Datapackge 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.13.1.tar.gz (47.2 kB view details)

Uploaded Source

Built Distributions

flatterer-0.13.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (55.6 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

flatterer-0.13.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (55.6 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

flatterer-0.13.1-cp310-none-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.10 Windows x86-64

flatterer-0.13.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (55.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

flatterer-0.13.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (13.7 MB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

flatterer-0.13.1-cp310-cp310-macosx_10_7_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.10 macOS 10.7+ x86-64

flatterer-0.13.1-cp39-none-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.9 Windows x86-64

flatterer-0.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (55.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

flatterer-0.13.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (13.7 MB view details)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

flatterer-0.13.1-cp39-cp39-macosx_10_7_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.9 macOS 10.7+ x86-64

flatterer-0.13.1-cp38-none-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.8 Windows x86-64

flatterer-0.13.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (55.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

flatterer-0.13.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (13.7 MB view details)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

flatterer-0.13.1-cp38-cp38-macosx_10_7_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

flatterer-0.13.1-cp37-none-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.7 Windows x86-64

flatterer-0.13.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (55.6 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

flatterer-0.13.1-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (13.7 MB view details)

Uploaded CPython 3.7m macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

flatterer-0.13.1-cp37-cp37m-macosx_10_7_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.7m macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: flatterer-0.13.1.tar.gz
  • Upload date:
  • Size: 47.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for flatterer-0.13.1.tar.gz
Algorithm Hash digest
SHA256 33891203b8ffd7c5b0054c2c4bb8dbedecd6e26bfadcec7c6f36d5ae524b6ff3
MD5 941ded77629e822e66772e7882c00063
BLAKE2b-256 1dd512632f75d211eb5f0fa8a94076ccdfd0c4203a73d9bb972be29df8c368c8

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b92134815a76642704b21b6fa861f5dd50848aa587e24c8f1092b195ca1014a3
MD5 bc60b89d55a0b5e063d7f98a34205c8e
BLAKE2b-256 b6c0fab40c2a2638d9eadf121bf6fa9620dff5869336404031cb579fc0469f7c

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3ab0e58f588edca8a6ccc397c255f2a5d76b7186cd62e447fe80c2214a1ed09d
MD5 63712afdc97089b4eeb5fa8621683799
BLAKE2b-256 126290beec2440671421a50772fbc068010ea28a95ea2d5240e4abedb1cec342

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 7ecf1b8cb6f62e995f69fa1c65ec6aaa499d7114b09e4a3cc8abe1ded624a260
MD5 8457d8598b4e9cf8ac2326a4018f9d83
BLAKE2b-256 a367afe5238a28d9b755990f49d75cabd4fee74b6128b5682f76af370f817568

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b9abe553d9fda7b4b10107e8f4c12529d69509b6bf66c1f078bfdb53616c4fdd
MD5 bea5e42d9a300b34ba139f47980e4a10
BLAKE2b-256 ca922b7a098db2040998560afc58f6ce9c52b54dca83ee2b01dfd81ff71ef485

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3a105a2ef4d79ae11db5ec20689b32e1aa53f9d710197b50752d973de87b3e47
MD5 770cd84d500088fa810e5dd27189cf01
BLAKE2b-256 ecc20264b18e81e95eb7b1b30f486af0205e5f358ee247b09510c31c4c85830b

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp310-cp310-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 310517cee57096570a976b98cd1b3db5d344451cb2838431478069f13c472ec7
MD5 2fed212c650269e85850809a965cfd73
BLAKE2b-256 d238d5bbef4a5698089ccd3cd91c6dbd85e7a48a92ca24a98e4b8cb0ffbf93a0

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 42a63606453828ee24ae75975699abc6f61efc529df224257515da54fb33e13d
MD5 a83ed18e9073ba239fd5e2a82f548fcb
BLAKE2b-256 cd2661dceebc64b44788e60213606314184bcdd44d8d07b24c99389b386a5e31

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 49faf4c0bea811eca1dcc2316c26469cf95c0ce15f3eae7b9ab29609c6c32410
MD5 728e5284133456608993596c3162639a
BLAKE2b-256 0490603b49bfd4de27ad1a9adaf9298e93579c241a6dadf4aad7d04189cbe0e4

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 55e5776c554e4a50c094bfd42d2546151526afc8acd1dde7042b84300be338f8
MD5 1ef543d8d7bb4b563a8dd32152ddb08b
BLAKE2b-256 4aa07179e160a2789f07d107d548180700d6e9a8dc4e9131d3ec5ea130c90fed

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp39-cp39-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 c45ea90514fd48195a77ff81ab8c897ccb505a7ba10e1be0f336c60c300687f2
MD5 4fdc1ce9fc3bb05acd99e8e51e259a1c
BLAKE2b-256 7ffc495bd93d6bca6b8c46e5a2e11b9be7dcc8911b5d2dbe0c4751f2c6ceaa84

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 4de884828b9e60937d88e8edaa98be601aac5f8a9792ced04dcb46453e3bdf72
MD5 155f93b4d7d69ba5198f353b18137d5a
BLAKE2b-256 ad03611c7040e0c09a3abe801b1155326019e69bbe741f409b0ac319bb1a9782

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a38dbe8713dd73fe4edfac98273b4800bfcf6084b4afe4ebd648c54bf10bd888
MD5 f58fa7d108202393c25233187e6c928a
BLAKE2b-256 cf597b355cdcafac18acc789aa4b76798b2d4c29a7b9acd17dfb29dea6b7efb5

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1f2dfe7194d260bc17ebed5b7ce218d3e903cc578d29b7e2b354b291b4cafc48
MD5 d0413a8415447a39fe06fbe3ff2ddc95
BLAKE2b-256 ecb5b46c3347bcd261ad822438c10b87838c3598cbe02afaf43c4c30e65defcc

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 78e89121c3368e7116fc223a89d443f5675338b6f8f8b7c2683567f11ca9b6c3
MD5 7ded37220990489afacd32a8b9baac52
BLAKE2b-256 2d062332706576c3b1c4512a06eadc14bc229223535ca29927224af61e9013a6

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp37-none-win_amd64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 e1fe1ceadce33fa55aab1a80cc2b225f8bef85acba88c51d9621d0c1cec02a69
MD5 e70801ffa4d5047f6beecbd8f15bbd63
BLAKE2b-256 da8fb5b87aa090e95f0b1054f26dcc373a8b1d7c1d03d8978bc7161ebffc4486

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4bdb3145fd548074bb0946a3b804b1e0749ec63e295bfa06a2ad05b4cfed0832
MD5 2413be3c09132fb9f34a72c497ad046b
BLAKE2b-256 47f827f84b1776350dc11ca52f127089d458b22cd3e3de032099f529410c3192

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 606642fc94c67008caf30fc718e2f369282ea87ae8cda302beab7c45c91896b7
MD5 857d4346fa70927965ffd39a00763388
BLAKE2b-256 6b10383c08f8530abb3727130e3f425e9437d54a625b3c07b2549f9397d3b694

See more details on using hashes here.

Provenance

File details

Details for the file flatterer-0.13.1-cp37-cp37m-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for flatterer-0.13.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 3352a30a3090d496a2a272f2251336afa8e684e4ece45b77fcba1eb552449572
MD5 c6fa915d331250e0b38cb5e32758b4b4
BLAKE2b-256 207ead1c7b2981cd746d27d04c9fc5bced785f5a5f1ae1e1c608669823364c0a

See more details on using hashes here.

Provenance

Supported by

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