5 unstable releases

new 0.8.0 Nov 6, 2024
0.7.1 Aug 13, 2024
0.7.0 Apr 25, 2024
0.1.1 Nov 21, 2023
0.1.0 Jul 23, 2023

#1736 in Parser implementations

Download history 105/week @ 2024-07-17 95/week @ 2024-07-24 70/week @ 2024-07-31 128/week @ 2024-08-07 490/week @ 2024-08-14 372/week @ 2024-08-21 568/week @ 2024-08-28 217/week @ 2024-09-04 730/week @ 2024-09-11 526/week @ 2024-09-18 644/week @ 2024-09-25 614/week @ 2024-10-02 581/week @ 2024-10-09 810/week @ 2024-10-16 703/week @ 2024-10-23 524/week @ 2024-10-30

2,793 downloads per month
Used in 5 crates (via dicom-dump)

MIT/Apache

2.5MB
34K SLoC

DICOM-rs json

crates.io Documentation

This sub-project is directed at users of the DICOM-rs ecosystem. It provides serialization of DICOM data to JSON and deserialization of JSON to DICOM data, as per the DICOM standard part 18 chapter F.

This crate is part of the DICOM-rs project.


lib.rs:

DICOM JSON module

This library provides serialization of DICOM data to JSON and deserialization of JSON to DICOM data, as per the DICOM standard part 18 chapter F.

The easiest path to serialization is in using the functions readily available to_string and to_value. Alternatively, DICOM data can be enclosed by a DicomJson value, which implements serialization and deserialization via Serde.

Example

To serialize an object to standard DICOM JSON:

let obj = InMemDicomObject::from_element_iter([
    InMemElement::new(tags::SERIES_DATE, VR::DA, "20230610"),
    InMemElement::new(tags::INSTANCE_NUMBER, VR::IS, "5"),
]);

let json = dicom_json::to_string(&obj)?;

assert_eq!(
    json,
    r#"{"00080021":{"vr":"DA","Value":["20230610"]},"00200013":{"vr":"IS","Value":["5"]}}"#
);

To turn DICOM JSON back into an in-memory object:

let json = r#"{
    "00080021": { "vr": "DA", "Value":["20230610"] },
    "00200013": { "vr": "IS", "Value":["5"] }
}"#;
let obj: InMemDicomObject = dicom_json::from_str(&json)?;

Use the DicomJson wrapper type for greater control on how to serialize or deserialize data:

let dicom_obj = dicom_json::DicomJson::from(&obj);
let serialized = serde_json::to_value(dicom_obj)?;

assert_eq!(
    serialized,
    serde_json::json!({
        "00080021": {
            "vr": "DA",
            "Value": [ "20230610" ]
        },
        "00200013": {
            "vr": "IS",
            "Value": [ "5" ]
        }
    }),
);

Dependencies

~7–13MB
~141K SLoC