4.5 | 2 ratings Rate this file 11 Downloads (last 30 days) File Size: 3.21 KB File ID: #25713 Version: 1.1
image thumbnail

Highly portable JSON-input parser


Nedialko (view profile)


02 Nov 2009 (Updated )

For any version of Matlab that may still be in use by the fileexchange community.

| Watch this File

File Information

The JSON quickly gains popularity for a good reason. To paraphrase Christophe Delord (http://christophe.delord.free.fr/tpg/)
JSON is born from a simple statement:
A simple human-like meta-language will quickly
justify its use in such cases as data exchange over the web (e.g. Google translate), configuration files, etc.



 for an example of AUTOMATIC, PORTABLE & REUSABLE creation of GUI sets for Matlab.
(Note: p_json.m is at the core of this example too)

Hence it is worth the while to provide this novel facility to the widest possible audience of Matlab users.

Based on work from:

http://www.mathworks.com/matlabcentral/fileexchange/ ::

 F.Glineur 23393-another-json-parser: Faster, Clearer & More robust than #20565
 J.Feenstra 20565-json-parser

This submission also provides a very simple (yet meaningful) use example (see also the screenshot).

Your test script (called a0t on the screenshot) may look like:

% ---------------------------------------------------------

fName = 'test02.jon';

fid = fopen(fName,'rt'); inString = fscanf(fid,'%c'); fclose(fid);

data = p_json(inString)

% ---------------------------------------------------------

and hence
inString == verbatim the 'test02.jon' TEXT input file,

provided in the .zip (see links below for more detail and more definitions):

% =========================================================
inString =

    "name": {"type":"string"},
    "age" : {"type":"integer",
   "type" : "object"
  "name" : "John Doe",
  "age" : 30

% =========================================================

*** See also:

Given the topical nature of the JSO notation we invite the user to take a look at places like:





Json Parser and (Another) Json Parser inspired this file.

This file inspired Rubik1 and Jso Nlab: A Toolbox To Encode/Decode Json Files In Matlab/Octave.

MATLAB release MATLAB 5.2 (R10)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
15 Jan 2012 Qianqian Fang

FYI, an optimized JSON parser, JSONlab, based on this work is available at


It is 10x to 100x faster. A JSON encoder is also provided in JSONlab.

Comment only
24 Aug 2010 Tanyer Alan

Tanyer Alan (view profile)

12 Apr 2010 Dustin

Dustin (view profile)

I kinda wish there were a more straight-forward way of accessing structs that live inside an array. For example, in a JSON string that has a series of unkeyed objects living in an array (i.e., "arrayName": [ {"color": "red"}, {"color": "green"}, {"color": "blue"} ]), accessing those objects is odd. Instead of using arrayName(i).color you must use arrayName{1,i}.color. Not a huge deal, just different than what I was expecting.

Other than that, it is very particular about properly-formatted JSON string inputs, and that's a good thing. Nice job.

03 Nov 2009 1.1

Corrected typos & added the auto-GUI example & its link

Contact us