Skip to content

Use Matlab internal json-encode functions instead of SPM routines #1311

@jan-petr

Description

@jan-petr

Description

Stop using SPM_JSONREAD as this tends to crash with certain illegal JSON formats. We'll switch to Matlab I/O and JSONDECODE and JSONENCODE

fileID = fopen('xxx.json','r');
txt = fscanf(fileID,"%s");
j = jsondecode(txt);
fclose(fileID);

I've tested that both functions run the same time, so time-wise we won't loose anything.

HENK: won't we have as side-effect that if something crashes in between fopen & fclose, this will be pain? The file would be locked, so you cannot easily remove e.g., the derivatives folder and rerun. You don't seem to have this issue with the current spm_jsonread MEX? But that is perhaps a small price to pay.

Or perhaps we can immediately close the fileID after reading it; same for writing.

JAN: We of course close it immediately, but the issue is not in doing it fast, but about catching potential issues. So all that's inbetween opening and closing of a file is in a try-catch and if something fails, we first close the file and then report an error. So there isn't really a possibility of keeping a file open. Besides - this is mainly a Windows problem.

fileID = fopen('xxx.json','r');
txt = fscanf(fileID,"%s");
fclose(fileID);
j = jsondecode(txt);

Tasks

  • Write a new function xASL_io_jsonread
  • Write a new function xASL_io_jsonwrite
  • Replace all spm_readjson
  • Replace all spm_writejson
  • Write a UT function with one correct and one incorrect JSON

How to test

  • Henk checks code
  • Unit testing with this new test runs through
  • Check flavors in develop
  • Flavors are still running fine in this branch?
  • Issues with the last flavor - Siemens_PCASL_3DGRASE_VB17A_TopUp_2
  • Should we remove this from the last lines of xASL_mex_compileAll about spm_jsonread. JAN: This is already removed!

Release notes

Use Matlab functions instead of SPM for I/O of JSON files.

Metadata

Metadata

Assignees

Labels

bidsMoving ExploreASL to BIDS compatibilitydataEverything data relatedoptimizationEnsure that code runs faster with unchanged functionality

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions