toJSON
Convert a Scilab variable to a JSON string.
Syntax
result = toJSON(var) result = toJSON(var, indent) toJSON(var, filename) toJSON(var, filename, indent) toJSON(var, indent, filename)
Arguments
- var
The Scilab variable to convert to JSON format.
- filename
File where to write the JSON string.
- indent
If this argument is given, the result is indented. The value is the number of spaces. 0 : No identation. (default) >0 : indentation with spaces.
- <opt_args>
This represents a sequence of statements
key1=value1, key2=value2, ...
wherekey1
,key2
, ... can be one of the following:- convertInfAndNaN
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
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().
Description
This function converts a Scilab variable into a JSON string or JSON file.
Examples
// 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)
See also
- http_post — HTTP POST request.
- http_put — HTTP PUT request.
- http_patch — HTTP PATCH request.
- http_delete — HTTP DELETE request.
- http_upload — HTTP POST or PUT request to upload file(s) on server.
- fromJSON — Convert JSON to a Scilab variable.
- http_get — HTTP GET request.
History
Версия | Описание |
6.1 | Function introduced. |
2023.0.0 | Handling of tabs (ascii(9)) changed. |
2024.1.0 | convertInfAndNaN option added. |
Report an issue | ||
<< http_upload | Web Tools | url_decode >> |