This project has moved. For the latest updates, please go here.

Editing JSON files in MATLAB with JSONlab

Aug 28, 2014 at 10:21 PM
Hi all,

I've been using the new version of the monte carlo command line tool, and using the JSON files instead the xml has been very nice indeed. However, I ran into a small problem.

As you know, the DetectorInputs part of the input file (as read in by loadjson) consists of a 1xn cell array, where n is the number of kinds of detectors and each cell contains a structure with the various properties of the detector. The trouble I'm having is that when I use savejson function to save a file with only one kind of detector, it flattens the cell array down to the underlying structure for the single detector. The command line tool of course does not like the missing cell array indicators and throws an error if you feed it the file.

Looking at the json file itself I discovered that this is basically just neglecting to put in a pair of square brackets, which I can add in manually just fine to solve the problem for now. I figured someone might have run into this problem already and have a more elegant solution though.
Aug 28, 2014 at 11:10 PM
Thanks for posting the issue! I wasn't aware that the 'savejson.m' method did this manipulation. There might be a way to configure the serialization to not do this. For reference, JSONLab is an open-source project hosted here:

Perhaps Qianqian or other JSONLab users would be willing to help us figure out how to achieve the desired result.