Collecting multiple .json objects in one .json file?

29 visualizaciones (últimos 30 días)
Claudio Esposito
Claudio Esposito el 1 de Nov. de 2021
Editada: Prince Kumar el 19 de Nov. de 2021
Hello everyone, I'm developing a deep learning Mask R-CNN training.
I have labeled images through imageLabeler and I got the annotations as gTruth file. Then I have converted these files in .json objects using the following code :
annotationsFileName='gTruth_coco.json';
exportGroundTruthToJSON(gTruth,annotationsFileName,'COCO',true)
Now, the problem is I have to collect these .json files in one .json file.
How can I do that?
Many thanks for your attention and your kind help.

Respuestas (1)

Prince Kumar
Prince Kumar el 17 de Nov. de 2021
Editada: Prince Kumar el 19 de Nov. de 2021
You can open the json files and append them one after another. Following is how you can achieve it.
st1 = fileread('data/label_data_1.json');
st2 = fileread('data/label_data_2.json');
[fid,msg] = fopen('combined.json','wt');
fprintf(fid,'%s\n%s',st1,st2);
fclose(fid);
Here 'combined.json' will be your desired json file.
To perform the above operation on Linux system without MATLAB, you may run the following commands in terminal
touch combined.json
cat data/label_data_1.json >> combined.json
cat data/label_data_2.json >> combined.json

Community Treasure Hunt

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

Start Hunting!

Translated by