Convert a Scilab variable to a JSON string.
result = toJSON(var) result = toJSON(var, indent) toJSON(var, filename) toJSON(var, filename, indent) toJSON(var, indent, filename)
The Scilab variable to convert to JSON format.
File where to write the JSON string.
If this argument is given, the result is indented. The value is the number of spaces. 0 : No identation. (default) >0 : indentation with spaces.
This represents a sequence of statements
key1=value1, key2=value2, ...
where key1,
key2, ... can be one of the following:
JSON specification does not allow writing NaN and Infinity values.
By default (convertInfAndNaN=%t) those values are converted into a JSON null value to follow the specification.
When this optional argument is set to %f, those values are stored in the JSON as literals: NaN, Infinity, and -Infinity.
result is a string that contains the data converted to JSON.
If a filename is given, no result is returned.
A Scilab scalar variable is converted into a single number without brackets. To force the brackets around, put the scalar into a list().
This function converts a Scilab variable into a JSON string or JSON file.
// structure st = struct("status", "OK", "value", 12); toJSON(st) // matrix toJSON([1, 2, 3]) // pretty print st = struct("test", ["a" "b"], "values", [1 2]); toJSON(st) toJSON(st, 4) // Scalar value toJSON(42) toJSON(list(42)) // non finite values toJSON([[%nan, 1]; [1e+380, 1e-380]; [%inf, -%inf]]) toJSON([[%nan, 1]; [1e+380, 1e-380]; [%inf, -%inf]], convertInfAndNaN=%f) | ![]() | ![]() |
| Version | Description |
| 6.1 | Function introduced. |
| 2023.0.0 | Handling of tabs (ascii(9)) changed. |
| 2024.1.0 | convertInfAndNaN option added. |