How to extract and open Json file in folder.
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
mohd akmal masud
el 17 de Sept. de 2024
Comentada: Walter Roberson
el 28 de Sept. de 2024
Dear All,
I have Json file in folder as attached. But, I tried to extract and open, it failed.
Some can help me?
2 comentarios
Epsilon
el 18 de Sept. de 2024
Please refer to the answer: https://www.mathworks.com/matlabcentral/answers/326764-how-can-i-read-a-json-file
If you are still facing issues, feel free to reply.
Walter Roberson
el 18 de Sept. de 2024
You have to start by doing
S = fileread(' DVK_Cu-64_0.1_adipose.json.zip');
T = jsondecode(S);
bytearray = matlab.net.base64decode(T.base64_zip_o__);
fid = fopen('test.zip', 'w');
fwrite(fid, bytearray);
fclose(fid)
This will give you a file test.zip that is in zip format.
Unfortunately it is corrupted zip format, and it is not clear how to get further than this.
Respuesta aceptada
Ishaan Mehta
el 24 de Sept. de 2024
Editada: Ishaan Mehta
el 24 de Sept. de 2024
Hello,
I tried to open the attached ZIP file "https://dvk_cu-64_0.1_adipose.json.zip" but was unable to do so. It seems that the ZIP file is corrupted.
However, as I understand, you wish to know how to read a JSON file in MATLAB, which is present in a ZIP file.
Firstly, we would need ot unizp the file to extarct the JSON file from it.
This can be done using the "unzip" function, which accepst a file name and unzips it in the current folder. If required, "cd" command can be used to move to the extracted folder where the JSON file resides.
Once you have the JSON file, one of the quickest ways to do read it is using the "readdictionary" function in MATLAB. This function accepts a JSON file name as input, and reads the content into a "dictionary" object in the MATLAB workspace. It takes care of assigning the most approriate data types for each value in the JSON object.
You can learn more about the mentioned functions in the following documentation pages:
- unzip: https://www.mathworks.com/help/matlab/ref/unzip.html
- cd: https://www.mathworks.com/help/matlab/ref/cd.html
- readdictionary: https://www.mathworks.com/help/matlab/ref/readdictionary.html
Hope this helps!
1 comentario
Walter Roberson
el 28 de Sept. de 2024
Firstly, we would need ot unizp the file to extarct the JSON file from it.
This will not work. The attached DVK_Cu-64_0.1_adipose.json.zip file is not a .zip file: it is a json encoded file. It starts with
{"base64(zip(o))": "eJxkvUuSLUmOZLmVpBpHGcn/09Ne
I described the steps needed to work with the file at https://www.mathworks.com/matlabcentral/answers/2153230-how-to-extract-and-open-json-file-in-folder#comment_3263965
Más respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Support Package for IP Cameras en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!