Great tool! I just found a small bug. The code fails to write a correct JSON object when there's an empty array (and probably also fails with an empty cell).
Line 29 in mat2json.m it reads:
J(end)=']';
When the array is empty, this line will replace the opening '[' with the closing ']' (there's no trailing comma to replace!). A simple length check or string comparison to handle this edge case should fix it.
Thanks for a very useful toolbox. I found a certain nesting of MATLAB structures and cell arrays which can not be taken for a round-trip to JSON and back. This snippet fails in the json2mat call: