View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.6 | 5 ratings Rate this file 22 Downloads (last 30 days) File Size: 12.9 KB File ID: #27169 Version: 1.0




This Matlab toolbox converts JSON formats into (json2mat) and from (mat2json) Matlab structures.

| Watch this File

File Information

Details and manual at project web page at: .

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
21 Feb 2017 maxwell pinz

function[FILEWRITE] = Json_space_remover(FILENAME)
% Removes leading spaces in Json files, allowing them to be read.
% Maxwell Pinz 2017 Johns hopkins University
fileID = fopen(FILENAME);
FID_write = fopen(FILEWRITE,'w');
C = textscan(fileID,'%s');
for ii = 1:length(C{1})
write_str = char(C{1}(ii));
fprintf(FID_write,'%s \n',write_str);

Comment only
21 Nov 2016 Gustavo Delfino

Please note that that is a newer version at:

Comment only
28 Aug 2013 Emmanuel Farhi

A very good read/write json support, which does not depend on any Java based library. Thanks.

19 Nov 2012 Jordi Riba

Sorry, did not wake up today ...
kk=json2mat ('xx.js',1)

Comment only
19 Nov 2012 Jordi Riba

Hi, this file works really good to extract data from json files!!!

However I try to assign the results to a variable (to avoid having it in ans= ...) and I cannot do it. Any ideas? Thanks.

17 Mar 2012 ted p teng

ted p teng (view profile)

05 Mar 2012 Jorge Herrera

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:


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.


29 Apr 2010 Jan Tore Korneliussen

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:

mystruct0_f1.fieldA = 'A';
mystruct0_f1.fieldB = 'B';
mystruct0.field0 = 1;
mystruct0.field1 = mystruct0_f1;

mystruct1_f3.fieldC = 'C';
mystruct1_f3.fieldD = 'D';
mystruct1.field2 = 2;
mystruct1.field3 = mystruct1_f3;

mycarr = {mystruct0, mystruct1};


The output:

??? Reference to non-existent element of a cell array.

Error in ==> json2mat at 23

Error in ==> json2mat>extract_struct at 60

Error in ==> json2mat at 23

Error in ==> json2mat>extract_cell at 70

Error in ==> json2mat at 26

Error in ==> jsontest at 13

Contact us