hMRI-group / hMRI-toolbox

A toolbox for quantitative MRI and in vivo histology using MRI (hMRI)
GNU General Public License v2.0
61 stars 44 forks source link

Error when reading JSON file #102

Closed NeuroimagingOL closed 1 month ago

NeuroimagingOL commented 2 months ago

Dear all,

I just started using the hMRI toolbox. I converted the DICOMS with the DICOM Import function implemented in SPM and the one implemented within the hMRI toolbox. However, in both cases, wenn I try to run the map creation there is an error that the json file cannot by read with. When I try to read it with get_metadata it says that the file is empty or corrupted.

I cannot find any differences in comparison to the example json-file downloadable from the website. I attached on of the json files I created with SPM here.

Can somebody find the error? sOL_3913-0015-00001-000224-01.json

Best regards, Tina

lukeje commented 2 months ago

I just opened the json file in vscode, and it is warning me that the "ImplementationVersionName" field contains an invalid character. Perhaps that is the source of the json reader not being able to read the file?

NeuroimagingOL commented 2 months ago

Thanks for you fast reply. You are right. The entry was 1.5.0/WIN32. It seems that the / is not working. When I replace it with \ it works.

Do you have an idea why this is happening? I assume I have to change that in every json file, or can that be avoided in the DICOM Import already?

Barisevrenugur commented 2 months ago

Dear @NeuroimagingOL , did this happen on Linux environment? Because windows uses / and Linux uses \ , and in certain file operations this can cause a problem.

NeuroimagingOL commented 2 months ago

I am using Windows. I just checked, the entry is already in the original DICOM header: ImplementationVersionName: '1.5.0/WIN32'

I just noticed that in all other fields where a / or \ occurs, it is a double \, like here: "ImageType": "ORIGINAL\PRIMARY\M\DIS2D".

I just see my previous answer was misleading, I changed it to \, not to a single one as written above.

lukeje commented 2 months ago

I don't know; I would guess the problematic character is already in the DICOM. Using \ instead of / will escape the problematic character, (you can already see in the json file that a literal "\" in a json string needs to be "\\") but I don't think it is to do with linux vs. windows paths, but rather linux vs. windows character encoding. For now I would just recommend editing the files (this should be possible in an automated way using command line tools), but perhaps you could check whether the tool you use to export DICOMs is mangling this field somehow.

Barisevrenugur commented 2 months ago

Dear @NeuroimagingOL ,

I can offer you the following matlab script which you can play with and possibly get you want: I tested it, it works BUT the final file is text instead of a struct... But i think by playing around with it, one should be able to get a struct in the end, the idea is to read the json file and to re-write it and then feed it to the toolbox:

myJsonFile = "sOL_3913-0015-00001-000224-01.json";
text = fileread(myJsonFile);
data = jsondecode(text)
myjsonnew = jsonencode(data);
spm_jsonwrite('data2.json', myjsonnew)
json3 = spm_jsonread('data2.json');
NeuroimagingOL commented 1 month ago

Dear all,

thanks for you help. I solved the problem with the following snipped:

jsonData = jsondecode(fileread('myjson.json'))); jsonData.acqpar.ImplementationVersionName = ['1.5.0\WIN32']; %here I changed the / to \ spm_jsonwrite('myjson,json',jsonData,struct('indent',' '));