Collecting multiple .json objects in one .json file?

12 次查看(过去 30 天)
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.

回答(1 个)

Prince Kumar
Prince Kumar 2021-11-17
编辑:Prince Kumar 2021-11-19
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