save json file to directory from workspace
18 views (last 30 days)
Show older comments
I've read a json file into a structure, edited the structure, re-encoded the structure as another json file in the workspace, then attempted to save it in the directory using the save function. It appears to have an issue here as instead of saving correctly it seems to be encoding wrong as shown below. first image is the view when i open the original json file which is correctly displayed. second image is the view when i open the new json file from the directory. it is stored correctly in the workspace so the issue is amost certainly from the save function - what is the correct method for saving the json file?
Thanks,


0 Comments
Accepted Answer
Jan
on 24 Mar 2018
Edited: Jan
on 24 Mar 2018
No, this is not a "wrong" encoding, but save stores the data in MAT file format. sav is simply the wrong function to store a JSON file.
What did you use to import the JSON file?
I'd start with searching in the net. I'd prefer a stable Java implementation like http://vision.is.tohoku.ac.jp/~kyamagu/software/json/. You find many other implementations in the FileExchange: https://www.mathworks.com/matlabcentral/fileexchange/?utf8=%E2%9C%93&term=json . JSONlab is frequently downloaded, but I'm not a fan of it because of the usage of global variables for the communication with the subfunctions. What a pity that such a huge and useful tool suffers from a design flaw.
4 Comments
Doaa Alamoudi
on 27 Apr 2021
To import json file to matlab
DF = 'filename.json';
fid = fopen(DF);
raw = fread(fid,inf);
str = char(raw');
data = jsondecode(str);
More Answers (0)
See Also
Categories
Find more on JSON Format in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!