jsonencode
- :
text =jsonencode(obj)¶ - :
text =jsonencode(…, "ConvertInfAndNaN", tf)¶ - :
text =jsonencode(…, "PrettyPrint", tf)¶ Encode the value obj as a JSON document, returned as a character row.
Numbers use the shortest text that reads back as the same value. Logical values become
trueandfalse, character rows become strings (a character matrix gives an array of strings), and empty arrays become[]. Vectors become flat arrays, matrices arrays of rows and N-dimensional arrays nested arrays whose indices followobj(i,j,k). A cell array becomes an array of its encoded elements, a scalar structure an object with the fields in order, and a structure array an array of objects. Atablebecomes a JSON array of row objects (always an array, even for height 0 or 1). Acontainers.Mapwith string keys becomes a JSON object.categoricalvalues become strings (or an array of strings),datetimevalues become theircharform, and enumeration members become their names. A leading run ofxHHHH_in a structure field name (the letterx, four hexadecimal digits and an underscore) is written as that Unicode code point, sox0024_typeis the key$typeandx0040_contextis@context. A field name that does not start with that pattern is written literally. Sparse input is encoded as the corresponding full array.NaN,Infand-Infare written asnull, unless"ConvertInfAndNaN"is false, in which case the wordsNaN,Infinityand-Infinityare used. With"PrettyPrint"true the result is indented by two spaces per level. Option names are not case sensitive.Complex numbers and function handles cannot be encoded.