Skip to main content

What does this tool do?

A specialized dictionary splitting tool that allows you to unpack a dictionary from its internal array or list values and generate a list. Each list will have a complete copy of all key-value pairs. It's somewhat similar to a matrix. This tool is designed to split arrays within JSON data into multiple records, making it easier to insert into a database.

Example

for list

data = {
    "id": 1, 
    "name": "John", 
    "subject": [{"id": 22, "des": "math"}, {"id": 23, "des": "art"}]
}

Allow overriding parent's same-named key-value pairs by default.

unpack(data, ["subject"])

Output:
[{'id': 22, 'name': 'John', 'des': 'math'},
{'id': 23, 'name': 'John', 'des': 'art'}]

Forbid overriding parent's same-named key-value pairs.

unpack(data, ["subject"], ".")

Output:
[{'id': 1, 'name': 'John', 'subject.id': 1, 'subject.name': 'John'},
{'id': 1, 'name': 'John', 'subject.id': 1, 'subject.name': 'John'}]

An empty list will be returned when a non-existent path is passed in.

unpack(data, ["subject", "name"], ".")

Output:
[]

For double-layer or multi-layer nesting

data = {
    "id": 1,
    "name": "John",
    "subject": [{
        "subjectid": 22,
        "des": [{"key": "a"},
                {"key": "b"}]
    }, {"subjectid": 23,
        "des": [{"key": "a"},
                {"key": "e"}]
        }]
}
unpack(data, ["subject"])

Output:
[
{'id': 1, 'name': 'John', 'subjectid': 22, 'des': [{'key': 'a'}, {'key': 'b'}]}, 
{'id': 1, 'name': 'John', 'subjectid': 23, 'des': [{'key': 'a'}, {'key': 'e'}]}
]
unpack(data, ["subject", "des"])

Output:
[
{'id': 1, 'name': 'John', 'subjectid': 22, 'key': 'a'}, 
{'id': 1, 'name': 'John', 'subjectid': 22, 'key': 'b'}, 
{'id': 1, 'name': 'John', 'subjectid': 23, 'key': 'a'}, 
{'id': 1, 'name': 'John', 'subjectid': 23, 'key': 'e'}
]

If it is empty, override the same-named key-value pairs in the parent. If it is not empty, use the provided string as the delimiter to connect with the parent key.

unpack(data, ["subject", "des"], "_")

Output:
[
{'id': 1, 'name': 'John', 'subject_subjectid': 22, 'subject_des_key': 'a'},
{'id': 1, 'name': 'John', 'subject_subjectid': 22, 'subject_des_key': 'b'},
{'id': 1, 'name': 'John', 'subject_subjectid': 23, 'subject_des_key': 'a'},
{'id': 1, 'name': 'John', 'subject_subjectid': 23, 'subject_des_key': 'e'}
]

for array

unpack(
dictionary = {"id": 1, "name": "John", "grades": [85, 92, 78]},
index      = ["grades"],
delimiter  = None
)

Array-type fields only allow single-level unpacking.

Output:
[
{"id": 1, "name": "John", "grade": 85},
{"id": 1, "name": "John", "grade": 92},
{"id": 1, "name": "John", "grade": 78}
]

Metadata

Release files for dict-unpack 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dict-unpack 0.0.2
File Size Uploaded Provenance Actions
dict_unpack-0.0.2.tar.gz 2.7 kB Without provenance Details for dict_unpack-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dict-unpack 0.0.2
File Interpreter ABI Platform Actions
dict_unpack-0.0.2-py3-none-any.whl Python 3 none any Details for dict_unpack-0.0.2-py3-none-any.whl

Total release size: 5.6 kB

Release files / dict_unpack-0.0.2.tar.gz

Download URL dict_unpack-0.0.2.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9850e91c6d5d09b93d2258094c8f8a3d04490583eb00bb4434fca42909c12a96
BLAKE2b-256 checksum
How to use checksums
3e96d2429eba399ceed7393946e6b4f1edf11ed96dbd773a0c44cf03d07717c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / dict_unpack-0.0.2-py3-none-any.whl

Download URL dict_unpack-0.0.2-py3-none-any.whl
Size 2.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e09f4f69e2adae525681645191f420dd976689758a9c7e8f7f153aa08bdca2ba
BLAKE2b-256 checksum
How to use checksums
111bda5eed7e73d98d520ec1d1a5a22fedea1ed2274538e5c0aedce98e338790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Security for dict-unpack 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page