Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

jsondecode

Decode JSON-formatted text

Syntax

value = jsondecode(text)

Description

example

value = jsondecode(text) parses JSON text.

Examples

collapse all

Display the JSON-formatted string ["one", "two", "three"].

jsondecode('["one", "two", "three"]')
ans = 3x1 cell array
    {'one'  }
    {'two'  }
    {'three'}

Input Arguments

collapse all

JSON-formatted text, specified as a character vector. Invalid names in the JSON text are made valid with matlab.lang.makeValidName.

Example: '{"IDs":[116,943,234,38793]}'

Data Types: char

Output Arguments

collapse all

MATLAB data returned as decoded JSON-formatted text. value depends on the data encoded in text.

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 booleans

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

Introduced in R2016b

Was this topic helpful?