moloney / dcmstack

DICOM to Nifti conversion with meta data preservation
Other
72 stars 51 forks source link

Object of type DcmMetaExtension is not JSON serializable #69

Closed Spenhouet closed 4 years ago

Spenhouet commented 4 years ago

I'm a bit confused to why the DcmMetaExtension is not JSON serializable.

The documentation states:

The dictionaries of summarized meta data are encoded with JSON.

I did expect the following to work:

json.dump(nifti_wrapper.meta_ext, configfile)

but I only get:

Object of type DcmMetaExtension is not JSON serializable

Spenhouet commented 4 years ago

I just found the .to_json() method in your code.

The working example then would be:

json.dump(nifti_wrapper.meta_ext.to_json(), configfile)

This answers my confusion.

I will close this issue but I want to note that I could not find this method in the documentation. You might want to add it there.

EDIT:

Also, .to_json() does not return a json object. You will have to also do this:

json.loads(nifti_wrapper.meta_ext.to_json())