File Exchange

image thumbnail

Parse JSON text

version 1.4 (24.5 KB) by

Convert data from JSON format to a MATLAB-usable variable.

21 Downloads

Updated

View License

Implemented as a MATLAB class, this file quickly and conveniently turns incoming streams of text into useful data for your MATLAB workspace.
This submission also contains an example/ directory and a test/ directory containing unit tests.

Comments and Ratings (2)

The JSON parser works very nicely, but due to the MathWorks Limited License, this code cannot be used (legally) within any project where the code is to be shared since giving copies of this code to third parties is prohibited. For open-source use this is especially inconvenient.
I think this is a bit unfortunate, since JSON data is widely available and MATLAB doesn't have a built-in parser.

Guy Ziv

Great submission. Needs two bug fixes - first, need to check fieldname does not start with a digit. Adding "fieldname = regexprep(fieldname,'(^\d)','s$1');" after line 154 of JSON.m will do.

Second, if JSON text has specific numeric values such 91 the code fails because it compares to '[' . Need to replace code pieces like "if value == '['" etc everywhere.

Updates

1.4

Fixed bugs described by Guy.
Numeric fields equal to the ASCII codes for special characters like {}[]: and , no longer fail.
Field names that start with numbers get an "s" prepended to them to form valid MATLAB fields.
Thanks Guy!

1.1

Minor update.

MATLAB Release
MATLAB 8.1 (R2013a)
Acknowledgements

Inspired: OpenSignals File Format Reader for BITalino

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

» Watch video