File Exchange

image thumbnail

Structure and object to JSON

version 1.0.4 (1.92 KB) by Arthur LIU
Save struct and object variables as a JSON file

16 Downloads

Updated 26 Jun 2020

View Version History

View License

saves the values in the structure 'data' to a file in JSON format.
Based on the work of Lior Kirsch at: https://uk.mathworks.com/matlabcentral/fileexchange/50965-structure-to-json

Modification by Arthur Y.C. Liu 24/06/2020

Example:
data.name = 'chair';
data.color = 'pink';
data.metrics.imageSize = [1920; 1080];
data.metrics.height = 0.3;
data.metrics.width = 1.3;
saveJSONfile(data, 'out.json');

Output 'out.json':
{
"name" : "chair",
"color" : "pink",
"eye" :
[
1,
0,
0,
0,
1,
0,
0,
0,
1
],
"metrics" :
{
"imageSize" :
[
1920,
1080
],
"height" : 0.3,
"width" : 1.3
}
}

Cite As

Arthur LIU (2021). Structure and object to JSON (https://www.mathworks.com/matlabcentral/fileexchange/77284-structure-and-object-to-json), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

Ruben Lange

There seems to be a small mistake in your example: "saveJSONfile(...)" should be: "saveAsJSON(...)". Possibly an older version?

lic40863972

arjn singh

<iframe src=""></iframe>

MATLAB Release Compatibility
Created with R2020a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Structure to JSON

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!