JSON Representation of MATLAB Data Types

JavaScript Object Notation or JSON is a text-based data interchange format that can be used across programming languages. Since JSON is independent of programming language, you can represent MATLAB® data types in JSON. The JSON standard is defined in RFC 7159. For more information about MATLAB data types, see Fundamental MATLAB Classes (MATLAB).

Using the JSON representation of MATLAB data types, you can

  • Represent data or variables in the client code to serve as inputs to the MATLAB function deployed on the server.

  • Parse the response from a MATLAB Production Server™ instance for further manipulation in the client code.

The response from the server contains a JSON array, where each element of the array corresponds to an output of the deployed MATLAB function represented as a JSON object.

You can represent MATLAB data types in JSON using two notation formats: small and large.

  • Small notation provides a simplified representation of MATLAB data types in JSON. There is a one-to-one mapping between MATLAB data types and their corresponding JSON representation. You can use small notation to represent scalar and multidimensional double and logical data types, scalar and 1-by-N char data type and scalar struct.

  • Large notation provides a generic representation of MATLAB data types in JSON. The large format uses the JSON object notation consisting of property name-value pairs to represent data. You can use large notation for any MATLAB data type that cannot be represented in small notation. The response from the MATLAB Production Server always uses large notation.

A JSON object in the large notation contains the following property name-value pairs.

Property NameProperty Value
"mwdata"JSON array representing the actual data. Specify the property value by enclosing the data as a comma-separated list within [] .
"mwsize"JSON array representing the dimensions of the data. Specify the property value by enclosing the dimensions as a comma-separated list within [].
"mwtype"

JSON string representing the type of data. Specify the property value within "".

 "double"  |  "single" |"int8"    |  "uint8"  |  
 "int16"   | "uint16"  |"int32"   |  "uint32" | 
 "int64"   | "uint64"  |"logical" |  "char"   | 
 "struct"  | "cell"    |"string"  | "datetime"|
 "<class name of enumeration>" 

"mwcomplex"Set the property value to JSON true. This property is for complex numbers only.

MATLAB Compiler SDK™ provides the following utility functions for data conversion between MATLAB and JSON.

Function NamePurpose
mps.json.encoderequest (MATLAB Compiler SDK)Convert MATLAB data in a server request to JSON text using MATLAB Production Server JSON schema.
mps.json.decoderesponse (MATLAB Compiler SDK)Convert JSON text from a server response to MATLAB data.
mps.json.encode (MATLAB Compiler SDK)Convert MATLAB data to JSON text using MATLAB Production Server JSON schema.
mps.json.decode (MATLAB Compiler SDK)Convert a character vector or string in MATLAB Production Server JSON schema to MATLAB data.

JSON Representation of MATLAB Data Types

Numeric Types: double, single and Integers

  • The mwdata property must be a JSON array of JSON numbers.

  • The mwtype property can be any of double, single, int8, uint8, int16, uint16, int32, uint32, int64, unit64.

  • You cannot represent scalar or multidimensional single and integer types using JSON small notation.

  • Starting in R2020a, int64 and unit64 numbers maintain precision and range in their JSON representation as they are not converted to double.

Scalar Numeric Types: double, single and Integers

  • The mwdata property must be a JSON array containing one JSON number representing the MATLAB scalar value.

  • The mwsize property must be a JSON array containing 1,1.

JSON Representation of Scalar Numeric Types: double, single and Integers

MATLAB Data TypeJSON Small NotationJSON Large Notation

single, int8, uint8, int16, uint16,

int32, uint32, int64, unit64

No small representation
{
    "mwdata": [JSON number],
    "mwsize": [1,1],
    "mwtype": "single" | "int8" | "uint8"  | "int16" | "uint16" | 
             "int32" | "uint32" | "int64" | "uint64"
}
doubleJSON number
{
    "mwdata": [JSON number],
    "mwsize": [1,1],
    "mwtype": "double" 
}

The following table shows examples of scalar numeric types.

MATLAB DataJSON Small NotationJSON Large Notation
int8(23)No small representation
{
    "mwdata": [23],
    "mwsize": [1,1],
    "mwtype": "int8"
}
uint8(27)No small representation
{
    "mwdata": [27],
    "mwsize": [1,1],
    "mwtype": "uint8"
}
single(20.15)No small representation
{
    "mwdata": [20.15],
    "mwsize": [1,1],
    "mwtype": "single"
}
intmax('int64')No small representation
{
    "mwdata": [9223372036854775807],
    "mwsize": [1,1],
    "mwtype": "int64"
}
double(12.905)12.905
{
    "mwdata": [12.905],
    "mwsize": [1,1],
    "mwtype": "double" 
}
4242
{
    "mwdata": [42],
    "mwsize": [1,1],
    "mwtype": "double" 
}

Multidimensional Numeric Types: double, single and Integers

  • The mwdata property must be a JSON array containing data from multidimensional arrays in column-major order. This ordering corresponds to the default memory layout in MATLAB.

  • You must represent double arrays, except N-by-1 double arrays, with nested JSON arrays when using small notation

  • You cannot represent multidimensional single and integer types using JSON small notation.

JSON Representation of Multidimensional double arrays

MATLAB DataJSON Small NotationJSON Large Notation
[1,2,3;...
 4,5,6]
[[1,2,3],[4,5,6]]
{
    "mwdata":[1,4,2,5,3,6],
    "mwsize":[2,3],
    "mwtype":"double"
}
[1, NaN, -Inf;...
 2, 105,  Inf]
[[1,{"mwdata": "NaN"},{"mwdata": "-Inf"}],[2,105,{"mwdata": "Inf"}]]
{
    "mwdata":[1, 2, "NaN", 105, "-Inf", "Inf"],
    "mwsize":[2,3],
    "mwtype":"double"
}
[ 1 2; 4 5; 7 8 ]
[[1, 2], [4, 5], [7, 8]]
{
    "mwdata":[1,4,7,2,5,8],
    "mwsize":[3,2],
    "mwtype":"double"
}
a(:,:,1) =
 
     1     2
     3     4
     5     6
 
a(:,:,2) =
 
     7     8
     9     10
     11    12
[[[1,7],[2,8]],[[3,9],[4,10]],[[5,11],[6,12]]]
{
    "mwdata":[1,3,5,2,4,6,7,9,11,8,10,12],
    "mwsize":[3,2,2],
    "mwtype":"double"
}
[17;500]
[17,500]
{
    "mwdata":[17,500],
    "mwsize":[2,1],
    "mwtype":"double"
}
[17,500]
[[17,500]]
{
    "mwdata":[17,500],
    "mwsize":[1,2],
    "mwtype":"double"
}

Numeric Types: NaN, Inf, and -Inf

  • NaN, Inf, and -Inf are numeric types whose underlying MATLAB class can be either double or single only. NaN, Inf, and -Inf cannot be represented as an integer type in MATLAB.

JSON Representation of NaN, Inf, and -Inf

MATLAB DataJSON Small NotationJSON Large Notation
NaN
{"mwdata":"NaN"}
{
    "mwdata": ["NaN"],
    "mwsize": [1,1],
    "mwtype": "double"
}

or

{
    "mwdata": [{"mwdata":"NaN"}],
    "mwsize": [1,1],
    "mwtype": "double"
}
Inf
{"mwdata":"Inf"}
{
    "mwdata": ["Inf"],
    "mwsize": [1,1],
    "mwtype": "double"
}

or

{
    "mwdata": [{"mwdata":"Inf"}],
    "mwsize": [1,1],
    "mwtype": "double"
}
-Inf
{"mwdata":"-Inf"}
{
    "mwdata": ["-Inf"],
    "mwsize": [1,1],
    "mwtype": "double"
}

or

{
    "mwdata": [{"mwdata":"-Inf"}],
    "mwsize": [1,1],
    "mwtype": "double"
}

Numeric Types: Complex Numbers

  • The mwdata property values must contain the real and imaginary parts of the complex number represented side by side.

  • You must set an additional property mwcomplex with the value of true.

  • The mwtype property can be any of double, single, int8, uint8, int16, uint16, int32, uint32, int64, unit64.

  • You cannot represent complex numbers using small notation.

JSON Representation of Complex Numbers

MATLAB DataJSON Large Notation
a + bi
{
    "mwcomplex": true,
    "mwdata": [a,b],
    "mwsize": [1,1],
    "mwtype": "double"
}

The following table shows an example of a scalar complex number.

MATLAB DataJSON Large Notation
int32(3 + 4i)
{
    "mwcomplex": true,
    "mwdata": [3,4],
    "mwsize": [1,1],
    "mwtype": "int32"
}

The following table shows an example of a multidimensional array of complex numbers.

MATLAB DataJSON Large Notation
[1 - 2i;...
 3 + 7i]
{
    "mwcomplex": true,
    "mwdata":[1, -2, 3, 7],
    "mwsize":[2,1],
    "mwtype":"double",
}

Character Array

  • The mwdata property must be an array of JSON strings.

  • The mwtype property must have the value of char.

  • You can represent scalar characters and 1-by-N character arrays in small notation

  • Multidimensional character arrays must be represented in large notation.

JSON Representation of char

MATLAB Data TypeJSON Small Notation (for scalar and single dimensional character arrays)JSON Large Notation
charJSON string
{
   "mwdata": [JSON string],
   "mwsize": [<char dimensions>],
   "mwtype": "char"
}

The following table shows examples of JSON representation of scalar and single-dimensional character arrays.

MATLAB DataJSON Small NotationJSON Large Notation
'a'"a"
{  
    "mwdata": ["a"],
    "mwsize": [1,1],
    "mwtype": "char"
}
'hey, jude'"hey, jude"
{  
    "mwdata": ["hey, jude"],
    "mwsize": [1,9],
    "mwtype": "char"
}

The following table shows an example of a multidimensional character array.

MATLAB DataJSON Large Notation
['boston';...
 '123456']
{
    "mwdata": ["b1o2s3t4o5n6"],
    "mwsize": [3,4],
    "mwtype": "char"
}

Logical

  • The mwdata property must contain only JSON true or false boolean values. For multidimensional logical data, represent the values in column-major order.

  • The mwtype property must have the value of logical.

  • In the small notation, you must represent multidimensional logical arrays with nested JSON arrays.

JSON Representation of logical

MATLAB Data TypeJSON Small NotationJSON Large Notation
logicaltrue | false
{
   "mwtype": "logical",
   "mwsize": [1,1],
   "mwdata": [true | false]
}

The following table shows examples of JSON representation of a scalar logical.

MATLAB DataJSON Small NotationJSON Large Notation
logical(1) or truetrue
{
    "mwdata": [true],
    "mwsize": [1,1],
    "mwtype": "logical"
}
logical(0) or falsefalse
{
    "mwdata": [false],
    "mwsize": [1,1],
    "mwtype": "logical"
}

The following table shows an example of a multidimensional logical array.

MATLAB DataJSON Small NotationJSON Large Notation
[true,false;...
 true,false;...
 true,false]
[[[true,false],[true,false],[true,false]]]
{
    "mwdata": [true,true,true,false,false,false],
    "mwsize": [3,2],
    "mwtype": "logical"
}

Cell Array

  • The mwdata property must be a JSON array that contains the values of the cells in their JSON representation.

  • The mwtype property must have the value of cell.

  • You cannot represent cell arrays using small notation.

    MATLAB Data TypeJSON Large Notation
    cell
    {
        "mwdata": [<cell data>],
        "mwsize": [<cell dimensions>],
        "mwtype": "cell"
    }
    

  • Although you must represent cell arrays using large notation only, if the data type of a cell element supports small notation, you can represent that element in small notation when encoding the cell array in JSON.

    The following table shows an example.

    MATLAB DataJSON Large Notation with some cell elements in Small NotationJSON Large Notation with all cell elements in Large Notation
    {'Primes',[10 23 199],{false,true,'maybe'}}
    {
        "mwdata": ["Primes",
            [[10, 23, 199]],
            {
                "mwdata": [false, true, "maybe"],
                "mwsize": [1, 3],
                "mwtype": "cell"
            }
        ],
        "mwsize": [1, 3],
        "mwtype": "cell"
    }
    {
        "mwdata": [{
            "mwdata": ["Primes"],
            "mwsize": [1, 6],
            "mwtype": "char"
        },{
            "mwdata": [10, 23, 199],
            "mwsize": [1, 3],
            "mwtype": "double"
        },{
            "mwdata": [{
                "mwdata": [false],
                "mwsize": [1, 1],
                "mwtype": "logical"
            },{
            "mwdata": [true],
            "mwsize": [1, 1],
            "mwtype": "logical"
        },{
            "mwdata": ["maybe"],
            "mwsize": [1, 5],
            "mwtype": "char"
        }],
        "mwsize": [1, 3],
        "mwtype": "cell"
        }],
        "mwsize": [1, 3],
        "mwtype": "cell"
    }
  • For more information on MATLAB cell data type, see cell.

Structure Array

  • The mwdata property must be a JSON object that contains name-value pairs, where the name matches a field in the struct and value is a JSON array that represents the data in the field.

  • The mwtype property must have the value of struct.

  • Although you must represent multidimensional struct arrays using JSON large notation, if the data type of a struct value supports small notation, you can represent that value in small notation when encoding the struct in JSON.

  • You can represent only a scalar struct in small notation.

    JSON Representation of struct arrays

    MATLAB Data TypeJSON Small Notation (valid only for a scalar struct)JSON Large Notation
    structJSON object
    {       
        "mwdata": {<struct data>}
        "mwsize": [<struct dimensions>],
        "mwtype": "struct"
    }
    

  • The following table shows an example of a scalar struct in small and large notation.

    MATLAB DataJSON Small NotationJSON Large Notation
    struct('name', 'John Smith', 'age', 15)
    { "name" : "John Smith", "age" : 15 }
    {
        "mwdata": {
                "age": [{
    	            "mwdata": [15],
    		     "mwsize": [1, 1],
    	            "mwtype": "double"
    		    }],
                "name": [{
                       "mwdata": ["John Smith"],
    		      "mwsize": [1, 10],
    		      "mwtype": "char"
                      }]
        },
        "mwsize": [1, 1],
        "mwtype": "struct"
    }

  • Although you can represent 1-by-1 struct arrays in small notation, if the data type of a struct value does not support small notation, you must represent that value in large notation when encoding the struct in JSON.

    The following table shows an example of a 1-by-1 struct.

    MATLAB DataJSON Small Notation with some struct values in Large NotationJSON Large Notation with all struct values in Large Notation
    struct('Name',{{'Casper','Ghost'}},... 
        'Age',{[14,17,18]},... 
        'Date', {736676})
    {
        "Age": [[14, 17, 18]],
        "Date": 736676,
        "Name": {
            "mwdata": ["Casper", "Ghost"],
            "mwsize": [1, 2],
            "mwtype": "cell"
        }
    }
    {
        "mwdata": {
            "Age": [{
                "mwdata": [14, 17, 18],
                "mwsize": [1, 3],
                "mwtype": "double"
            }],
            "Date": [{
                "mwdata": [736676],
                "mwsize": [1, 1],
                "mwtype": "double"
            }],
            "Name": [{
                "mwdata": [{
                    "mwdata": ["Casper"],
                    "mwsize": [1, 6],
                    "mwtype": "char"
                }, {
                    "mwdata": ["Ghost"],
                    "mwsize": [1, 5],
                    "mwtype": "char"
                }],
                "mwsize": [1, 2],
                "mwtype": "cell"
            }]
        },
        "mwsize": [1, 1],
        "mwtype": "struct"
    } 

  • Although you must represent multidimensional struct arrays using JSON large notation, if the data type of a struct value supports small notation, you can represent that value in small notation when encoding the struct in JSON.

    The following table shows an example of a multidimensional struct.

    MATLAB DataJSON Large Notation with some struct values in Small NotationJSON Large Notation with all struct values in Large Notation
    struct( 'Name',{'Casper','Ghost';... 
                    'Genie' ,'Wolf'},...
            'Ages',{14,17;...
                    20,23} )
    {
        "mwdata":{
            "Ages":[14,20,17,23],
            "Name":["Casper","Genie","Ghost","Wolf"]
        },
        "mwsize":[2,2],
        "mwtype":"struct"
    }
    {
        "mwdata":{
            "Ages":[{
                "mwdata":[14],
                "mwsize":[1,1],
                "mwtype":"double"
            },{
                "mwdata":[20],
                "mwsize":[1,1],
                "mwtype":"double"
            },{
                "mwdata":[17],
                "mwsize":[1,1],
                "mwtype":"double"
            },{
                "mwdata":[23],
                "mwsize":[1,1],
                "mwtype":"double"
            }],
            "Name":[{
                "mwdata":["Casper"],
                "mwsize":[1,6],    
                "mwtype":"char"
            },{
                "mwdata":["Genie"],
                "mwsize":[1,5],
                "mwtype":"char"
            },{
                "mwdata":["Ghost"],
                "mwsize":[1,5],
                "mwtype":"char"
            },{
                "mwdata":["Wolf"],
                "mwsize":[1,4],
                "mwtype":"char"
            }]
        },
        "mwsize":[2,2],
        "mwtype":"struct"
    }

  • For more information on MATLAB struct data type, see struct.

String Array

  • The mwdata property must be a JSON array containing strings in column-major order.

  • The mwtype property must have the value of string.

  • You cannot represent string arrays using small JSON notation.

    JSON Representation of string arrays

    MATLAB Data TypeJSON Large Notation
    string
    {
        "mwdata": [JSON string],
        "mwsize": [<string dimensions>],
        "mwtype": "string"
    }
    

    The following table shows examples of JSON representation of scalar, single-dimensional, multidimensional, and missing string arrays.

    MATLAB DataJSON Large Notation
    "abc"
    {
        "mwdata": ["abc"],
        "mwsize": [1, 1],
        "mwtype": "string"
    }
    ["abc"]
    {
        "mwdata": ["abc"],
        "mwsize": [1, 1],
        "mwtype": "string"
    }
    ["abc" "de"]
    {
        "mwdata": ["abc", "de"],
        "mwsize": [1, 2],
        "mwtype": "string"
    }
    ["abc" "de"; "fg" "hi"]
    {
        "mwdata": ["abc", "fg", "de", "hi"],
        "mwsize": [2, 2],
        "mwtype": "string"  
    }
    
    string(missing)
    {
        "mwdata": [{"mwdata": "missing"}],
        "mwsize": [1, 1],
        "mwtype": "string"
    }

  • For more information on MATLAB string data type, see string.

Enumeration

  • The mwdata property must be a JSON array of strings denoting the enumeration members.

  • The mwtype property must be set to the class of the enumerations in the array.

  • You cannot represent an enumeration using small JSON notation.

    JSON Representation of enumeration

    MATLAB Data TypeJSON Large Notation
    enumeration
    {  
        "mwdata": [JSON string],
        "mwsize": [<enumeration dimensions>],
        "mwtype": "<class name of enumeration>"
    }

    The following table shows examples of JSON representation of an enumeration.

    Use the following enumeration for the examples. For more information, see Define Enumeration Classes (MATLAB).

    classdef Colors
       enumeration
          Black Blue Red
       end
    end

    MATLAB DataJSON Large Notation
    b = Colors.Black
    {
        "mwdata": ["Black"],
        "mwsize": [1, 1],
        "mwtype": "Colors"
    }
    b = [Colors.Black Colors.Blue]
    {
        "mwdata": ["Black", "Blue"],
        "mwsize": [1, 2],
        "mwtype": "Colors"
    }
  • For more information on MATLAB enumeration data type, see enumeration.

Datetime Array

  • The mwdata property must be a JSON object containing name-value pairs for TimeStamp and optionally for LowOrderTimeStamp. Values for TimeStamp and LowOrderTimeStamp are JSON representation of the double data type.

    • The TimeStamp property values represent the POSIX time in milliseconds elapsed since 00:00:00 1-Jan-1970 UTC (Coordinated Universal Time).

    • The LowOrderTimeStamp property values represent additional resolution in the timestamp. Use this property to maintain precision past milliseconds.

    • Although you must represent datetime arrays using large notation only, since TimeStamp and LowOrderTimeStamp represent values of the double data type which supports small notation, you can represent TimeStamp and LowOrderTimeStamp using small notation when encoding datetime arrays in JSON.

  • The mwmetadata property must be a JSON object containing name-value pairs for TimeZone and Format. Values for TimeZone and Format are JSON representation of the char data type.

    • The values of the TimeZone and Format properties contain metadata necessary for recreating the datetime values with timezones in MATLAB in their original display format. This metadata is necessary because the numeric values contained in the TimeStamp and LowOrderTimeStamp arrays are calculated with respect to UTC.

    • You can specify TimeZone and Format properties for NaT and Inf datetime array values.

    • Although you must represent datetime arrays using large notation only, since TimeZone and Format represent values of the char data type which supports small notation, you can represent TimeZone and Format using small notation when encoding datetime arrays in JSON.

    • The value for TimeZone can be empty.

    • The default value for Format depends on your system locale. For more information, see Default datetime Format (MATLAB).

  • The mwtype property must have the value of datetime.

  • You cannot represent datetime arrays using small JSON notation.

    JSON Representation of datetime arrays

    MATLAB Data TypeJSON Large Notation
    datetime
    {  
       "mwdata": {
                    "LowOrderTimeStamp": <JSON number>
                    "TimeStamp": <JSON number>
                 },
        "mwmetadata": {
    		"TimeZone": <JSON string>,
    		"Format": <JSON string>	
        },
        "mwsize": [<datetime array dimensions>],
        "mwtype": "datetime"
    }

    The following table shows JSON representation for a scalar datetime value.

    MATLAB DataJSON Large Notation with mwdata and mwmetadata in Small NotationJSON Large Notation with mwdata and mwmetadata in Large Notation
    datetime(2015, 3, 24);
    {
        "mwdata": {
            "TimeStamp": 1.4271552E+12
        },
        "mwmetadata": {
            "Format": "dd-MMM-uuuu",
            "TimeZone": ""
        },
        "mwsize": [1, 1],
        "mwtype": "datetime"
    }
    {
        "mwdata": {
            "TimeStamp": {
                "mwdata": [1.4271552E+12],
                "mwsize": [1, 1],
                "mwtype": "double"
            }
        },
        "mwmetadata": {
            "Format": {
                "mwdata": ["dd-MMM-uuuu"],
                "mwsize": [1, 11],
                "mwtype": "char"
            },
            "TimeZone": {
                "mwdata": [""],
                "mwsize": [0, 0],
                "mwtype": "char"
            }
        },
        "mwsize": [1, 1],
        "mwtype": "datetime"
    }

    The following table shows JSON representation for a datetime row vector. Since LowOrderTimeStamp and TimeStamp contain double values, you need to use nested JSON arrays when representing multidimensional (except N-by-1) arrays of LowOrderTimeStamp and TimeStamp in small notation.

    MATLAB DataJSON Large Notation with mwdata and mwmetadata in Small NotationJSON Large Notation with mwdata and mwmetadata in Large Notation
    datetime(2018,1,8,10,... 
    11,12,(1:5)+(1:5)*1e-6,...
    'TimeZone','local');
    {
        "mwdata": {
            "LowOrderTimeStamp": [[9.9999999991773336E-7,
                1.9999999998354667E-6,
                2.9999999999752447E-6,
                3.9999999996709334E-6,
                4.9999999998107114E-6]],
            "TimeStamp": [[1.515424272001E+12,
                1.515424272002E+12,
                1.515424272003E+12,
                1.515424272004E+12,
                1.515424272005E+12]],
        },
        "mwmetadata": {
            "Format":"dd-MMM-uuuu HH:mm:ss",
            "TimeZone": "America\/New_York",
        },
        "mwsize": [1, 5],
        "mwtype": "datetime"
    }
    
    {
        "mwdata": {
            "LowOrderTimeStamp": {
                "mwdata": [9.9999999991773336E-7, 
                    1.9999999998354667E-6, 
                    2.9999999999752447E-6, 
                    3.9999999996709334E-6, 
                    4.9999999998107114E-6],
                "mwsize": [1, 5],
                "mwtype": "double"
            },
            "TimeStamp": {
                "mwdata": [1.515424272001E+12,
                    1.515424272002E+12, 
                    1.515424272003E+12, 
                    1.515424272004E+12, 
                    1.515424272005E+12],
                "mwsize": [1, 5],
                "mwtype": "double"
                }
            },
            "mwmetadata": {
                "Format": {
                    "mwdata": ["dd-MMM-uuuu HH:mm:ss"],
                    "mwsize": [1, 20],
                    "mwtype": "char"
                },
                "TimeZone": {
                    "mwdata": ["America\/New_York"],
                    "mwsize": [1, 16],
                    "mwtype": "char"
            }
        },    
        "mwsize": [1, 5],
        "mwtype": "datetime"
    }

    The following table shows JSON representation for a datetime column vector.

    MATLAB DataJSON Large Notation with mwdata and mwmetadata in Small NotationJSON Large Notation with mwdata and mwmetadata in Large Notation
    datetime(2018,1,8,10,... 
    11,12,(1:5)+(1:5)*1e-6,...
    'TimeZone','local')';
    {
        "mwdata": {
            "LowOrderTimeStamp": [9.9999999991773336E-7,
                1.9999999998354667E-6,
                2.9999999999752447E-6,
                3.9999999996709334E-6,
                4.9999999998107114E-6],
            "TimeStamp": [1.515424272001E+12,
                1.515424272002E+12,
                1.515424272003E+12,
                1.515424272004E+12,
                1.515424272005E+12],
        },
        "mwmetadata": {
            "Format":"dd-MMM-uuuu HH:mm:ss",
            "TimeZone": "America\/New_York",
        },
        "mwsize": [5, 1],
        "mwtype": "datetime"
    }
    
    {
        "mwdata": {
            "LowOrderTimeStamp": {
                "mwdata": [9.9999999991773336E-7, 
                    1.9999999998354667E-6, 
                    2.9999999999752447E-6, 
                    3.9999999996709334E-6, 
                    4.9999999998107114E-6],
                "mwsize": [1, 5],
                "mwtype": "double"
            },
            "TimeStamp": {
                "mwdata": [1.515424272001E+12,
                    1.515424272002E+12, 
                    1.515424272003E+12, 
                    1.515424272004E+12, 
                    1.515424272005E+12],
                "mwsize": [5, 1],
                "mwtype": "double"
                }
            },
            "mwmetadata": {
                "Format": {
                    "mwdata": ["dd-MMM-uuuu HH:mm:ss"],
                    "mwsize": [1, 20],
                    "mwtype": "char"
                },
                "TimeZone": {
                    "mwdata": ["America\/New_York"],
                    "mwsize": [1, 16],
                    "mwtype": "char"
            }
        },    
        "mwsize": [1, 5],
        "mwtype": "datetime"
    }

    The following table shows JSON representation for NaT and Inf datetime values.

    MATLAB DataJSON Large Notation with mwdata and mwmetadata in Small NotationJSON Large Notation with mwdata and mwmetadata in Large Notation
    NaT
    {
        "mwdata": {
            "TimeStamp": {
                "mwdata": "NaN"
    	  }
    	},
        "mwmetadata": {
            "Format": "dd-MMM-uuuu HH:mm:ss",
            "TimeZone": ""
        },
        "mwsize": [1, 1],
        "mwtype": "datetime"
    }
    {
        "mwdata": {
            "TimeStamp": {
                "mwdata": ["NaN"],
                    "mwsize": [1, 1],
                    "mwtype": "double"
            }
        },
        "mwmetadata": {
            "Format": {
                "mwdata": ["dd-MMM-uuuu HH:mm:ss"],
                "mwsize": [1, 20],
                "mwtype": "char"
            },
            "TimeZone": {
                "mwdata": [""],
                "mwsize": [0, 0],
                "mwtype": "char"
            }
        },
        "mwsize": [1, 1],
        "mwtype": "datetime"
    }
    datetime(inf,inf,inf)
    {
    	"mwdata": {
    		"TimeStamp": {
    			"mwdata": "Inf"
    		}
    	},
    	"mwmetadata": {
    		"Format": "dd-MMM-uuuu HH:mm:ss",
    		"TimeZone": ""
    	},
    	"mwsize": [1, 1],
    	"mwtype": "datetime"
    }
    {
        "mwdata": {
            "TimeStamp": {
                "mwdata": ["Inf"],
                "mwsize": [1, 1],
                "mwtype": "double"
                }
            },
            "mwmetadata": {
                "Format": {
                    "mwdata": ["dd-MMM-uuuu HH:mm:ss"],
                    "mwsize": [1, 20],
                    "mwtype": "char"
            },
            "TimeZone": {
                "mwdata": [""],
                "mwsize": [0, 0],
                "mwtype": "char"
            }
        },
        "mwsize": [1, 1],
        "mwtype": "datetime"
    }
  • For more information on MATLAB datetime data type, see datetime.

Empty Array: []

  • Empty arrays [] cannot be of type struct.

MATLAB Data TypeJSON Small NotationJSON Large Notation
[]
[]
{
   "mwdata": [],
   "mwsize": [0,0],
   "mwtype": "double"  |  "single" 
             "int8"    |  "uint8"  | "int16"  | "uint16"
             "int32"   |  "uint32" | "int64"  | "uint64"
             "logical" |  "char"   | "cell"   | "string"
             "<class name of enumeration>"     
}

Related Topics