Skip to main content

json2rust

Turns a JSON document into a struct for rust-lang

Installation

From the project root directory:

$ python setup.py install

Or:

$ pip install json2rust

Usage

Simply run it with the name of the root struct and the path to your JSON:

$ json2rust MyStruct data.json

Use –help/-h to view info on the arguments:

$ json2rust --help

Example

Take your JSON doc:

$ cat testdata/example.json
{
        "name": "Me",
        "age": 33,
        "children": [
                {
                        "name": "joe",
                        "age": 0.5,
                        "exists": false
                }
        ],
        "job": {
                "employer": "foo",
                "salary": 5000000,
                "coworker": null
        }
}

Run json2rust:

$ json2rust ExampleStruct testdata/example.json
pub struct ExampleStruct {
        pub job: Job,
        pub age: i32,
        pub name: String,
        pub children: Vec<Children>,
}
pub struct Job {
        pub salary: i32,
        pub coworker: Option<UNKNOWN_NULL>,
        pub employer: String,
}
pub struct Children {
        pub age: f32,
        pub name: String,
        pub exists: bool,
}

Release Notes

0.1.0:

Project works

0.0.1:

Project created

Metadata

Release files for json2rust 0.2.0

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

Source distribution (sdist)

Source distribution for json2rust 0.2.0
File Size Uploaded Provenance Actions
json2rust-0.2.0.tar.gz 3.2 kB Without provenance Details for json2rust-0.2.0.tar.gz

Release files / json2rust-0.2.0.tar.gz

Download URL json2rust-0.2.0.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8ed2a70c9a820be19cbc8571ad32e0afd993b3bcb5ba7b1f0aa578434acd0242
BLAKE2b-256 checksum
How to use checksums
eeaf9c90b8770448a19c5eaaa4bd0a997cd27391d3953ec0affbf869639b3d35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.3

Security for json2rust 0.2.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.

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