Collecting multiple .json objects in one .json file?

12 Ansichten (letzte 30 Tage)
Claudio Esposito
Claudio Esposito am 1 Nov. 2021
Bearbeitet: Prince Kumar am 19 Nov. 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.

Antworten (1)

Prince Kumar
Prince Kumar am 17 Nov. 2021
Bearbeitet: Prince Kumar am 19 Nov. 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