Convert the string representation of a Python dictionary to JSON
You've got a Python dictionary that was printed to a log file. You want to run it through JSON tools, like jq but it's not actually JSON.
This command line tool allows you convert to JSON.
Why?
If you're the owner of a python script that writes simply does print(str(d)) you should consider changing it to use print(json.dumps(d)) instead.
However, you're not always the owner of scripts you use and you can't always change the code.
Instead, convert from the python string representation of a dictionary to JSON.
Examples
$ cat input.txt
{'example': {'number': 42, 'text': 'lorem ipsum', 'boolean': True}}
Let's convert it to JSON with:
$ cat input.txt | python3 -m pydict2json
{"example": {"number": 42, "text": "lorem ipsum", "boolean": true}}
That's hard to read, let's pretty print:
$ cat input.txt | python3 -m pydict2json --pretty
{
"example": {
"number": 42,
"text": "lorem ipsum",
"boolean": true
}
}
Much better.
Now that it's JSON we can use all our favorite JSON tools like jq:
$ cat input.txt | python3 -m pydict2json | jq .example.number
42
The tool also supports input directly on the command line:
$ python3 -m pydict2json --literal "{'a': None}"
{"a": null}
Metadata
Release files for pydict2json 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydict2json-0.1.0.tar.gz | 4.1 kB | Without provenance | Details for pydict2json-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydict2json-0.1.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for pydict2json-0.1.0-py2.py3-none-any.whl |
Total release size: 8.0 kB
Release files / pydict2json-0.1.0.tar.gz
| Download URL | pydict2json-0.1.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef77949e73a0255a7b1ebf5cc4b4425f75bd841f39f13f0ff917f152c650e957
|
|
BLAKE2b-256 checksum How to use checksums |
3eb2afccfddc06cd55ceb19bb11cb335335681529f23cf393f765984c51f724c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
|
Release files / pydict2json-0.1.0-py2.py3-none-any.whl
| Download URL | pydict2json-0.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
70dbefc869ad39355a62b623d8065efff1c347ef43ff2c388ed627d132260dce
|
|
BLAKE2b-256 checksum How to use checksums |
08f0c046fe499e05b01bc6f48cc65ffb14d921e458b4d76f623d01c906a86d85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
|
Security for pydict2json 0.1.0
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.