FUNCTION REFERENCE
jsondecode
Decode JSON text into arrays, structs and cells.
Decode JSON text into arrays, structs and cells.
Syntax
v = jsondecode(txt)Syntax
v = jsondecode(txt, 'makeValidName', false)txt is a character vector or string scalar holding one JSON value. An object becomes a scalar struct; member names that are not valid field names are changed the way matlab.lang.makeValidName does it (spaces removed with the next letter capitalized, other bad characters replaced by '_', an 'x' put in front of names that do not start with a letter), and repeated names get _1, _2, ... added. With 'makeValidName', false an invalid name is an error. null becomes [], true and false become logical scalars, numbers become double and strings become character vectors. An array of numbers becomes a column vector (null inside it is NaN), an array of booleans a logical column, and nested arrays of equal length become a matrix or N-D array whose first dimension is the outer array. An array of objects that all have the same member names becomes an N-by-1 struct array; any other array becomes an N-by-1 cell array. The words NaN, Inf, Infinity and -Infinity are accepted as numbers.
Example
s = jsondecode('{"name":"pump","rate":[1.5,2,null],"on":true}') % struct with fields name, rate (3x1, NaN last) and onExample
m = jsondecode('[[1,2,3],[4,5,6]]') % 2-by-3 doubleExample
c = jsondecode('[1,"two",[3,4]]') % 3-by-1 cellExample
s = jsondecode('{"first name":1,"2nd":2}') % fields firstName and x2ndDifferences from MATLAB: Arrays of objects nested inside arrays become cells of struct columns, not N-D struct arrays. An array holding only nulls becomes a cell of [] values. Results obey this engine's bounds: character vectors up to 65536 characters and cells or structs nested at most 16 levels; JSON text up to 64 MiB.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.