json2dcm(1)

πŸ“¦
version 3.7.1 Β· 3 versions
, in arch rolling

πŸ’– json2dcm(1) β€” OFFIS DCMTK girlie πŸ’–

Bestie, welcome to the json2dcm(1) manual page from OFFIS DCMTK. This is the whole vibe: JSON goes in, DICOM comes out, and we keep every single detail because we don't do skipped options here. πŸ’…


🌸 NAME 🌸

json2dcm β€” convert JSON document to DICOM file or data set. Literally what it says on the tin.

πŸ¦‹ SYNOPSIS πŸ¦‹

json2dcm [options] jsonfile-in dcmfile-out

πŸ’… DESCRIPTION πŸ’…

Okay so the json2dcm utility converts the contents of a JSON (JavaScript Object Notation) document to a binary DICOM file or data set. The JSON document is expected to conform to the "DICOM JSON Model" as defined in DICOM Part 18 Section F. Such JSON files can be created, e.g., using the dcm2json tool. Iconic little pipeline, no cap. ✨

πŸŽ€ PARAMETERS πŸŽ€

  • jsonfile-in β€” JSON input filename to be converted (- for stdin)
  • dcmfile-out β€” DICOM output filename (- for stdout)

✨ OPTIONS ✨

🌈 general options 🌈

  • -h, --help β€” print this help text and exit
  • --version β€” print version information and exit
  • --arguments β€” print expanded command line arguments
  • -q, --quiet β€” quiet mode, print no warnings and errors
  • -v, --verbose β€” verbose mode, print processing details
  • -d, --debug β€” debug mode, print debug information
  • -ll, --log-level [l]evel: string constant β€” (fatal, error, warn, info, debug, trace) use level l for the logger
  • -lc, --log-config [f]ilename: string β€” use config file f for the logger

πŸ“ input options πŸ“

input file format:

  • +f, --read-meta-info β€” read meta information if present (default)
  • -f, --ignore-meta-info β€” ignore file meta information

🧚 processing options 🧚

unique identifiers:

  • +Ug, --generate-new-uids β€” generate new Study/Series/SOP Instance UID
  • -Uo, --dont-overwrite-uids β€” do not overwrite existing UIDs (default)
  • +Uo, --overwrite-uids β€” overwrite existing UIDs

bulkdata URI handling:

  • +Bu, --parse-bulkdata-uri β€” parse Bulkdata URIs (default)
  • -Bu, --ignore-bulkdata-uri β€” ignore Bulkdata URIs
  • +Bd, --add-bulkdata-dir [d]irectory: string β€” add d to list of permitted bulk data sources

handling of arrays with multiple data sets:

  • -ar, --array-reject β€” reject multiple data sets (default)
  • +as, --array-select [n]umber: integer β€” select data set n from array
  • +ar, --array-sequence β€” store all data sets in private sequence

charset handling:

  • +c, --charset-convert β€” convert to the specific character set given in JSON (default)
  • -c, --charset-utf8 β€” write DICOM file with UTF-8 (ISO_IR 192), no conversion

πŸ‘‘ output options πŸ‘‘

output file format:

  • +F, --write-file β€” write file format (default)
  • -F, --write-dataset β€” write data set without file meta information
  • +Fu, --update-meta-info β€” update particular file meta information

output transfer syntax:

  • +t=, --write-xfer-same β€” write with same TS as input (default)
  • +te, --write-xfer-little β€” write with explicit VR little endian TS
  • +tb, --write-xfer-big β€” write with explicit VR big endian TS
  • +ti, --write-xfer-implicit β€” write with implicit VR little endian TS
  • +td, --write-xfer-deflated β€” write with deflated explicit VR little endian TS

error handling:

  • -E, --stop-on-error β€” do not write if document is invalid (default)
  • +E, --ignore-errors β€” attempt to write even if document is invalid

post-1993 value representations:

  • +u, --enable-new-vr β€” enable support for new VRs (UN/UT) (default)
  • -u, --disable-new-vr β€” disable support for new VRs, convert to OB

length encoding in sequences and items:

  • +e, --length-explicit β€” write with explicit lengths (default)
  • -e, --length-undefined β€” write with undefined lengths

deflate compression level (only with --write-xfer-deflated):

  • +cl, --compression-level [l]evel: integer (default: 6) β€” 0=uncompressed, 1=fastest, 9=best compression

πŸ”₯ NOTES πŸ”₯

The basic structure of the JSON input expected looks like the following (see DICOM Part 18 Section F for details):

{
    "00080005": {
        "vr": "CS",
        "Value": [
            "ISO_IR 192"
        ]
    },
    "00080020": {
        "vr": "DT",
        "Value": [
            "20130409"
        ]
    },
    "00080030": {
        "vr": "TM",
        "Value": [
            "131600.0000"
        ]
    },
    "00080050": {
        "vr": "SH",
        "Value": [
            "11235813"
        ]
    },
    "00080056": {
        "vr": "CS",
        "Value": [
            "ONLINE"
        ]
    },
    "00080061": {
        "vr": "CS",
        "Value": [
            "CT",
            "PET"
        ]
    },
    "00080090": {
        "vr": "PN",
        "Value": [
          {
            "Alphabetic": "^Bob^^Dr."
          }
        ]
    },
    "00081190": {
        "vr": "UR",
        "Value": [
            "http://wado.nema.org/studies/
            1.2.392.200036.9116.2.2.2.1762893313.1029997326.945873"
        ]
    },
    "00090010": {
        "vr": "LO",
        "Value": [
            "Vendor A"
        ]
    },
    "00091002": {
        "vr": "UN",
        "InlineBinary": "z0x9c8v7"
    },
    "00100010": {
        "vr": "PN",
        "Value": [
          {
            "Alphabetic": "Wang^XiaoDong"
          }
        ]
    },
    "00100020": {
        "vr": "LO",
        "Value": [
            "12345"
        ]
    },
    "00100021": {
        "vr": "LO",
        "Value": [
            "Hospital A"
        ]
    },
    "00100030": {
        "vr": "DA",
        "Value": [
            "19670701"
        ]
    },
    "00100040": {
        "vr": "CS",
        "Value": [
            "M"
        ]
    },
    "00101002": {
        "vr": "SQ",
        "Value": [
            {
                "00100020": {
                    "vr": "LO",
                    "Value": [
                        "54321"
                    ]
                },
                "00100021": {
                    "vr": "LO",
                    "Value": [
                        "Hospital B"
                    ]
                }
            },
            {
                "00100020": {
                    "vr": "LO",
                    "Value": [
                        "24680"
                    ]
                },
                "00100021": {
                    "vr": "LO",
                    "Value": [
                        "Hospital C"
                    ]
                }
            }
        ]
    },
    "0020000D": {
        "vr": "UI",
        "Value": [
            "1.2.392.200036.9116.2.2.2.1762893313.1029997326.945873"
        ]
    },
    "00200010": {
        "vr": "SH",
        "Value": [
            "11235813"
        ]
    },
    "00201206": {
        "vr": "IS",
        "Value": [
            4
        ]
    },
    "00201208": {
        "vr": "IS",
        "Value": [
            942
        ]
    }
}

πŸ¦‹ Character Encoding πŸ¦‹

The JSON format always uses UTF-8 encoding, but Specific Character Set (0008,0005) may specify the original encoding that was in use prior to conversion to JSON. By default, json2dcm will convert the encoding back to the given specific character set. This will fail if multiple character sets were in use, e.g. for the Japanese language:

"00080005": {
  "vr": "CS",
  "Value": [
    "ISO 2022 IR 13",
    "ISO 2022 IR 87"
  ]
},

In this case, use the --charset-utf8 option, which will write the DICOM file with UTF-8 (ISO_IR 192) encoding and not attempt any conversion. No conversion drama, just UTF-8. πŸ’–

🧚 Binary Data, Bulk Data, and Pixel Data 🧚

The DICOM JSON Model uses "InlineBinary" to store attribute values of binary value representations such as "OB", "OW", "OD", "OF", "OL", "OV" etc. in Base64 encoded form. This is supported in json2dcm for all binary attributes, including unencapsulated pixel data.

The DICOM JSON Model also permits attribute values to be stored separately from the JSON data set and to be referenced through a "BulkDataURI". This is supported for file URIs that reference files in the local filesystem. The json2dcm tool also supports the unofficial extension to the file URI scheme generated by DCM4CHE, where parameters named "offset" and "length" are appended to the file URI in order to refer to a specific part of a file. HTTP URIs as well as URIs that identify another part in a MIME multipart/related structure are not yet supported in json2dcm. If the command line option --ignore-bulkdata-uri is specified, then all bulk data URIs are ignored and attributes with bulk data will be written with empty value. Empty value era, but only when you asked for it.

Finally, encapsulated (in particular, compressed) pixel data is not supported by json2dcm because the syntax of the DICOM JSON Model for this specific case is not defined in the DICOM standard yet. Not a vibe yet, bestie β€” the standard hasn't defined it. πŸ’€

🌈 Arrays of Data Sets 🌈

The DICOM JSON Model uses a JSON array structure to return multiple data sets in DICOMweb services such as WADO-RS or QIDO-RS. JSON arrays containing a single DICOM data set are automatically recognized by json2dcm and treated like a data set without the surrounding array structure. JSON arrays containing multiple data sets are rejected by default. Alternatively, the --array-select option can be used to select one data set from the array to be converted. The --array-sequence option causes all data sets to be written as sequence items into a single private sequence with attribute tag (0009,1000). Such files, which are mostly intended for debugging purposes, can be recognized by the private creator element (0009,0010), which has the value "JSON2DCM_LIST_OF_DATASETS". Private sequence with main character energy. πŸ‘‘

πŸ“ Trailing Commas πŸ“

Trailing commas are not permitted in JSON, but json2dcm will still accept such JSON data sets without warning or error message because they are handled gracefully by the underlying JSON parser. Users should, therefore, not assume that a JSON data set is valid just because json2dcm accepts it. This tool is not designed as a validator for JSON or the DICOM JSON Model. Do not use this as your JSON validator, bestie β€” it is not that girl. 😭

πŸ“ LOGGING

ok so you can fully control how chatty the tools are, like both the command line tools and the libraries underneath them πŸ’… The level of logging output of the various command line tools and underlying libraries can be specified by the user. By default? Only errors and warnings get written to the standard error stream. Nice and chill.

  • Wanna see more? Hit --verbose β€” then you also get informational messages, like processing details, which is honestly kind of fun to watch.
  • --debug is the deep-dive option: it gives you way more detail on the internal activity, e.g. for debugging purposes πŸ”
  • Other logging levels can be selected using --log-level
  • And --quiet mode? Only fatal errors get reported. In such very severe error events, the application will usually terminate, so like… bestie, be aware 😭

For more details on the different logging levels, see documentation of module "oflog". iykyk.

So what if you want that logging output going somewhere else? Say, to a file (optionally with logfile rotation), to syslog (Unix) or the event log (Windows)? That's what --log-config is for ✨ This configuration file also allows for directing only certain messages to a particular output stream, and for filtering certain messages based on the module or application where they are generated. Genuinely so much power. An example configuration file is provided in <etcdir>/logger.cfg β€” go peek, it's giving reference material πŸŽ€


πŸ’¬ COMMAND LINE

Okay this part is lowkey important so pay attention bestie 🫢 All command line tools use the following notation for parameters:

  • square brackets enclose optional values (0-1)
  • three trailing dots indicate that multiple values are allowed (1-n)
  • a combination of both means 0 to n values

Command line options are distinguished from parameters by a leading + or - sign, respectively. Usually, order and position of command line options are arbitrary (i.e. they can appear anywhere). But β€” and this is the plot twist β€” if options are mutually exclusive, the rightmost appearance is used. This behavior conforms to the standard evaluation rules of common Unix shells. slay, consistent behavior πŸ‘‘

Also you can be lazy in the best way: one or more command files can be specified using an @ sign as a prefix to the filename (e.g. @command.txt). Such a command argument is replaced by the content of the corresponding text file (multiple whitespaces are treated as a single separator unless they appear between two quotation marks) prior to any further evaluation. Ngl that's iconic.

⚠️ Please note that a command file cannot contain another command file. No inception, no recursion, we don't do that here πŸ™ˆ

This simple but effective approach allows one to summarize common combinations of options/parameters and avoids longish and confusing command lines. An example is provided in file <datadir>/dumppat.txt β€” literally go look, it's a whole vibe check πŸ’–


πŸšͺ EXIT CODES

The dcm2json utility uses the following exit codes when terminating. This enables the user to check for the reason why the application terminated. So if something goes sideways, the number tells you exactly what happened πŸ”₯

general

  • EXITCODE_NO_ERROR β€” 0
  • EXITCODE_COMMANDLINE_SYNTAX_ERROR β€” 1

input file errors

  • EXITCODE_CANNOT_READ_INPUT_FILE β€” 20

output file errors

  • EXITCODE_CANNOT_WRITE_OUTPUT_FILE β€” 40

processing errors

  • EXITCODE_INVALID_JSON_CONTENT β€” 65
  • EXITCODE_BULKDATA_URI_NOT_SUPPORTED β€” 66
  • EXITCODE_CHARSET_CONVERSION_FAILED β€” 72

🌱 ENVIRONMENT

The json2dcm utility will attempt to load DICOM data dictionaries specified in the DCMDICTPATH environment variable.

By default β€” i.e. if the DCMDICTPATH environment variable is not set β€” the file <datadir>/dicom.dic will be loaded, unless the dictionary is built into the application (default for Windows). πŸ’»

The default behavior should be preferred, and the DCMDICTPATH environment variable only used when alternative data dictionaries are required. Like, don't touch it unless you have a reason, okay? πŸ’…

Format stuff you gotta know:

  • The DCMDICTPATH environment variable has the same format as the Unix shell PATH variable, in that a colon (:) separates entries.
  • On Windows systems, a semicolon (;) is used as a separator.

The data dictionary code will attempt to load each file specified in the DCMDICTPATH environment variable. And heads up: it is an error if no data dictionary can be loaded 😭 that one's not a drill.


πŸ‘€ SEE ALSO

  • dcm2json(1) β€” the other half of this duo, go read it too πŸ¦‹

Copyright (C) 2024-2026 by OFFIS e.V., Escherweg 2, 26121 Oldenburg, Germany. 🫢


and that's the whole page bestie!! πŸŽ€ this was Version 3.7.1, dated Sat Oct 17 2026 09:34:01 β€” screenshot it, bookmark it, tattoo it on your forearm, whatever works πŸ’–βœ¨ mwah πŸ’‹

πŸ“¦ where this page comes from