How to use Dicom.Serialization.JsonDicomConverter

1,327 views
Skip to first unread message

Luis Miguel Bustamante Palacio

unread,
Mar 8, 2018, 5:21:28 AM3/8/18
to Fellow Oak DICOM
Please help me.

I want to export and import dicom file, I want to use a template dicom to modify patient data and late add image.

How can I export a dicom file to json.

How can I use Dicom.Serialization.JsonDicomConverter.

Thanks all.

reini....@aon.at

unread,
Mar 13, 2018, 5:36:53 AM3/13/18
to Fellow Oak DICOM
The fo-dicom sources also include some unit tests. You can take a look at the unit tests that test the serialization to see how the JsonDicomConverter is used:


for example these lines of code:
            var json = JsonConvert.SerializeObject(originalDataset, new JsonDicomConverter());
var reconstituatedDataset = JsonConvert.DeserializeObject<DicomDataset>(json, new JsonDicomConverter());


Luis Miguel Bustamante Palacio

unread,
Mar 13, 2018, 2:49:10 PM3/13/18
to Fellow Oak DICOM
Works correctly. Thank you very much.

stephen fogarasi

unread,
Jan 31, 2023, 10:58:26 AM1/31/23
to Fellow Oak DICOM
I could not get the above to work. I have the latest fo-dicom (fo-dicom.core 5.0.3.0). Im basically trying to convert a dicom file to json and back :

...
using Dicom;
using FellowOakDicom.IO.Buffer;
using FellowOakDicom.Serialization;
using Newtonsoft.Json;
using Dicom.Serialization;
....

        private void TestFODJsonConversion(String filename)
        {
            byte[] buff = File.ReadAllBytes(filename);
            var stream = new MemoryStream(buff);
            DicomFile df = DicomFile.Open(stream, FileReadOption.SkipLargeTags);
            String json = JsonConvert.SerializeObject(df, new Dicom.Serialization.JsonDicomConverter());
            DicomDataset recoveredDs = JsonConvert.DeserializeObject<DicomDataset>(json, new JsonDicomConverter());
***EXCEPTION THROWN***

            DicomFile recoveredDf = new DicomFile(recoveredDs);
        }


Exception thrown: 'System.InvalidOperationException' in Newtonsoft.Json.dll
An exception of type 'System.InvalidOperationException' occurred in Newtonsoft.Json.dll but was not handled in user code
Cannot access child value on Newtonsoft.Json.Linq.JValue.

Also, looking at the created json file, it has a structure that I have not seen in other dicom json files, specifically, splitting the meta tags and image tags into separate blocks and other high level nestings. Am I missing some component ?

thx

stephen fogarasi

unread,
Jan 31, 2023, 11:26:30 AM1/31/23
to Fellow Oak DICOM
Also, I get the same error if I try to read a dicom json file created by dcm4che, and from public json dicom data.
Reply all
Reply to author
Forward
0 new messages