save json file to directory from workspace
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
George Swindells
il 24 Mar 2018
Commentato: Doaa Alamoudi
il 27 Apr 2021
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 Commenti
Risposta accettata
Jan
il 24 Mar 2018
Modificato: Jan
il 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 Commenti
Doaa Alamoudi
il 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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su JSON Format in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!