jsondecode - Decode JSON-formatted text - MATLAB (original) (raw)
Main Content
Decode JSON-formatted text
Syntax
Description
[value](#bvb7de1-value) = jsondecode([txt](#bvb7de1-text))
parses JSON text.
Examples
Display the JSON-formatted string ["one", "two", "three"]
.
jsondecode('["one", "two", "three"]')
ans = 3×1 cell {'one' } {'two' } {'three'}
Input Arguments
JSON-formatted text, specified as a string scalar or character vector. Invalid names in the JSON text are made valid withmatlab.lang.makeValidName
.
Example: '{"IDs":[116,943,234,38793]}'
Data Types: char
Output Arguments
MATLAB data returned as decoded JSON-formatted text.value
depends on the data encoded intxt.
Limitations
- If you decode, then encode a value, MATLAB does not guarantee that the result is identical to the original string. In particular, field names in JSON objects that are not valid MATLAB identifiers might be altered by the
makeValidName
function.
Algorithms
JSON supports fewer data types than MATLAB. jsondecode
converts JSON data types to the MATLAB data types in this table. jsondecode
converts JSON object field names to MATLAB structure field names.
JSON Data Type | MATLAB Data Type |
---|---|
null, in numeric arrays | NaN |
null, in nonnumeric arrays | Empty double [] |
Boolean | Scalar logical |
Number | Scalar double |
String | Character vector |
Object (In JSON, object means an unordered set of name-value pairs.) | Scalar structure (Names are made valid using matlab.lang.makeValidName.) |
Array, when elements are of different data types | Cell array |
Array of boolean | Array of logical |
Array of numbers | Array of double |
Array of strings | Cell array of character vectors |
Array of objects — Same field names | Structure array |
Array of objects — Different field names | Cell array of scalar structures |
Extended Capabilities
Version History
Introduced in R2016b