convert nested json to flat objects and their mapping
Project description
json_relational: Transforming Nested JSON to Relational Format
json_relational
is a small Python package for converting complex, nested JSON data into a flat, relational format. This transformation makes it significantly easier to work with JSON data in contexts where relational databases are more suitable, such as SQL databases. The package is designed to be dynamic and flexible, accommodating various levels of nested structures and converting them into a format that can be easily mapped to SQL tables.
Features
- Dynamic Nesting Handling: Effortlessly manages various levels of nested JSON data.
- SQL Table Ready: Transforms JSON into a format that is easily convertible to SQL tables.
- Customizable Depth Control: Set the maximum depth for flattening nested structures.
- Key Mapping Support: Allows for the remapping of keys to desired names in the output.
Installation
To install json_relational
, clone the repository from GitHub and install it using pip:
git clone https://github.com/gr0vity-dev/json-relational.git
cd json_relational
pip install .
Usage
Here's a simple example to demonstrate how json_relational
can be used to transform nested JSON data into a relational format:
from json_relational import JsonRelational
import json
# Example JSON data
json_data = {
"type": "employee",
"id": 123,
"data": {
"department": "sales",
"manager": "Bob"
}
}
# Create an instance of JsonRelational
jr = JsonRelational()
# Flatten the JSON data
flattened_data = jr.flatten_json(json_data)
print(json.dumps(flattened_data, indent=4))
Output:
The output will be a dictionary containing flattened data, along with mappings and accumulated children, ready to be transformed into SQL tables.
{
"log": [
{
"sql_id": 1,
"type": "employee",
"id": 123
}
],
"data": [
{
"sql_id": 1,
"department": "sales",
"manager": "Bob"
}
],
"mappings": [
{
"main_type": "log",
"main_sql_id": 1,
"link_type": "data",
"link_sql_id": 1
}
]
}
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check issues page.
License
Distributed under the MIT License. See LICENSE
for more information.
json_relational
offers an innovative solution for managing and transforming JSON data into a relational structure, making it an invaluable tool for database management, data analysis, and software development involving complex JSON data structures.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file json_relational-0.0.3.tar.gz
.
File metadata
- Download URL: json_relational-0.0.3.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d90141bc33f437281f05da55dce80ac4b3301952b1dedacad411e7733b06b37 |
|
MD5 | baa3c2cb1d52b0bfa9c831dd73981738 |
|
BLAKE2b-256 | 3a9090b927ffdfb835f3c0f157bba4b9f518c371042204f0806758e5970ce1d0 |
File details
Details for the file json_relational-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: json_relational-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e66d50bfc518fdc8a2ef30df435b3ad4529b421aa69edc8bd7964193d7fda8b |
|
MD5 | 8c1589d17b8cd823bdaa6049f3f77cea |
|
BLAKE2b-256 | 5630ae0fba0996fe9abac0b24a35ab62060cc3aa32be8455c1c04e395ed5d730 |