Writes a single variable to a JSON file.
Syntax |
Description |
---|---|
jsonwrite("filename", var); |
Writes the variable "var" to a json file. The variable can be declared in the command and can be a struct, cell, matrix, or string. |
Example
The following code example shows how to write the variable "a" to a json file.
# Create a variable a a = [1+2i, 3+4i]; jsonwrite("test_jsonwrite.json", a);
Creates the following json file.
{
"_complex" : true,
"_data" : [ 1.0, 2.0, 3.0, 4.0 ],
"_size" : [ 1, 2 ],
"_type" : "matrix"
}
The following code example shows how to define and write a struct to a json file with the jsonwrite command.
jsonwrite("test_jsonwrite.json", {"a":1, "b":"a string"});
Creates the following json file.
{
"a" : 1.0,
"b" : "a string"
}
See Also
jsonload , jsonloads , jsonsaves , jsonread, jsonreads, jsonwrites, JSON files