Skip to main content

Simple query language to extract tables from JSON.

Project description

json_tabulator

A simple query language for extracting tables from JSON-like objects.

Working with tabular data is much easier than working with nested documents. json-tables helps to extract tables from JSON-like objects in a simple, declarative manner. All further processing is left to the many powerful tools that exist for working with tables, such as Spark or Pandas.

Installation

Install from pypi:

pip install json_tabulator

Quickstart

The json_tabulator module provides tools to extract a JSON document into a set of related tables. Let's start with a simple document

data = {
    'id': 'doc-1',
    'table': [
        {'id': 1, 'name': 'row-1'},
        {'id': 2, 'name': 'row-2'}
    ]
}

The document consists of a document-level value id as well as a nested sub-table table. We want to extract it into a single table, with the global value folded into the table.

To do this, we write a query that defines the conversion into a table like this:

from json_tabulator import query

my_query = query({
    'document_id': 'id',
    'row_id': 'table.*.id',
    'row_name': 'table.*.name'
})

rows = my_query.execute(data)

This returns an iterator of rows, where each row is a dict {<column_name>: <value>}:

>>> list(rows)
[
    {'document_id': 'doc-1', 'row_id': 1, 'row_name': 'row-1'},
    {'document_id': 'doc-1', 'row_id': 2, 'row_name': 'row-2'}
]

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

json_tabulator-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

json_tabulator-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file json_tabulator-0.1.0.tar.gz.

File metadata

  • Download URL: json_tabulator-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.9.7 Darwin/22.5.0

File hashes

Hashes for json_tabulator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4ccaf9a2dffdf01f54389e717ad4ef537fe3d974367ecf83832b3b1ce08d08bd
MD5 d83d7360fc5f44a763f138b6f0d4f64c
BLAKE2b-256 b1baa714fc73ea99011b94214c7e53673d574e945874976dc9431a46acd2c66c

See more details on using hashes here.

File details

Details for the file json_tabulator-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: json_tabulator-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.9.7 Darwin/22.5.0

File hashes

Hashes for json_tabulator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 642dbc4fa11123cbf3179a835cd7aa4de1ba27d8490328a605f972beda706b63
MD5 80fa2d55ac7e685457331e526cf3d734
BLAKE2b-256 d3d3de5685e7a06c6064c74f7ca4c94617d8500facdbd907b087f44acf7ee8a2

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