<< jsondecode | JavaScript Object Notation | jsonprettyprint >> |
res = jsonencode(obj) |
res = jsonencode(obj, 'ConvertInfAndNaN', true_or_false) |
a Nelson object: struct, cell, matrix.
a logical: if true, Inf, NaN are converted to 'Inf' or 'Nan'.
a string: JSON text.
jsonencode converts a Nelson variable to JSON text.
jsonencode does not support complex numbers, sparse arrays, function handle, and others handle.
jsonencode can be overloaded to manage your own type.
By default jsonencode Inf values are converted to the string "Inf", NaN values are converted to 'null'.
Warning: The shape of a matrix and data type are not always preserved.
field1 = 'f1'; value1 = zeros(1,10);
field2 = 'f2'; value2 = {'a', 'b'};
field3 = 'f3'; value3 = {pi, pi*pi};
field4 = 'f4'; value4 = {'fourth'};
s = struct(field1,value1,field2,value2,field3,value3,field4,value4);
r = jsonencode(s)
filewrite([tempdir(), 'example.json'], r);
Version | Description |
---|---|
1.0.0 | initial version |
Allan CORNET