Skip to main content

A library for transforming nested JSON data into relational tables and back

Project description

dict2rel

PyPI - Version PyPI - Python Version codecov

dict2rel is a Python library which can transform JSON with any level of nesting into one or more tables which contain enough information that the tables can be modified and then converted back to the nested JSON format. Essentially, JSON can be converted to relational tables and then back.


Table of Contents

Installation

pip install dict2rel

Quick Start

from dict2rel import dict2rel
import pandas as pd  # you can also use polars.DataFrame

tables = dict2rel(
    [
        {
            "name": "relay-settings",
            "version": {
                "major": 1,
                "minor": 12,
                "patch": 1
            },
            "settings": [
                {
                    "key": "tempo",
                    "value": 12
                },
                {
                    "key": "delay",
                    "value": 14
                }
            ]
        },
        {
            "name": "response-settings",
            "version": {
                "major": 12,
                "minor": 0,
                "patch": 3
            },
            "settings": [
                {
                    "key": "throttle",
                    "value": "always"
                },
                {
                    "key": "burst",
                    "value": 0.43
                }
            ]
        },
    ],
    pd.DataFrame  # the tables will be of this type
)

tables will end up being a dict of the following tables:

*

name version.major version.minor version.patch _id
relay-settings 1 12 1 0
response-settings 12 0 3 1

*.settings

key value _id
tempo 12 0.settings.0
delay 14 0.settings.1
throttle always 1.settings.0
burst 0.43 1.settings.1

These tables can then be modified, maybe by adding a new column:

tables["*.settings"]["added"] = ["2025-12-18"] * len(tables["*.settings"])

and then converted back to nested JSON:

from dict2rel import rel2dict

transformed_data = rel2dict(tables)

which gives the following JSON:

[
    {
        "name": "relay-settings", 
        "version": {"major": 1, "minor": 12, "patch": 1}, 
        "settings": [
            {"key": "tempo", "value": 12, "added": "2025-12-18"}, 
            {"key": "delay", "value": 14, "added": "2025-12-18"}
        ]
    }, 
    {
        "name": "response-settings", 
        "version": {"major": 12, "minor": 0, "patch": 3}, 
        "settings": [
            {"key": "throttle", "value": "always", "added": "2025-12-18"}, 
            {"key": "burst", "value": 0.43, "added": "2025-12-18"}
        ]
    }
]

License

dict2rel is distributed under the terms of the MIT license.

Development

Make sure to run hatch fmt, hatch run black:run, hatch run test:run, and hatch run docs:build.

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

dict2rel-0.0.3.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

dict2rel-0.0.3-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file dict2rel-0.0.3.tar.gz.

File metadata

  • Download URL: dict2rel-0.0.3.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dict2rel-0.0.3.tar.gz
Algorithm Hash digest
SHA256 51ce9911ec281a0e09c663344487161c7f54c863f4b9b78d6078f01f69cd01b4
MD5 f556bac20f2394c5720e6be6e23f636e
BLAKE2b-256 d6f8459c29ae9da0ca75476aa1f0fea3d1ab465b151201c51017df068089a0d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for dict2rel-0.0.3.tar.gz:

Publisher: publish.yml on BlendingJake/Dict2Rel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dict2rel-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: dict2rel-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dict2rel-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6b3886dbec28a185f210d8c79e67347aa6c9563146b66f862a1a613be34398eb
MD5 e1e9d12890dd1adc05bef6a7bddb91b3
BLAKE2b-256 0d6d365f8ba8c3f47c027b4d782bbcc48b89438d6bf02d2bd5868b9d46a3229c

See more details on using hashes here.

Provenance

The following attestation bundles were made for dict2rel-0.0.3-py3-none-any.whl:

Publisher: publish.yml on BlendingJake/Dict2Rel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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