combine multi json files and convert to a csv file
**Start a discussion about anything you would like**
Discussions can be used to ask questions, discuss new ideas, or anything else.
Hi,

I'm a user of plantcv and python in general. I'm following the seed_size_plantcv_analysis.py script that I cloned from https://github.com/danforthcenter/plantcv-seeds. Also, I'm applying the seed image provided in the data folder of plantcv.

After editing the script based on the new updated pcv functions, I was able to get a json file for each analyze_object (i.e., seed) as follows:

for i in range(0, len(roi_objects)):
    if roi_obj_hierarchy[0][i][3] == -1:  # Checks if shape is a parent contour
                                        
        # Object combine kept objects
        obj, mask2 = pcv.object_composition(img, [roi_objects[i]], np.array([[roi_obj_hierarchy[0][i]]]))
        
        if obj is not None:
            analysis_image = pcv.analyze_object(img, obj, mask2)
            
            # Add custom output
            pcv.outputs.add_observation(
                    variable='filename',
                    trait='roi',
                    method='roi',
                    scale='int',
                    datatype=int,
                    value=i,
                    label='#')
            
            # At this point we have observations for one plant
            # We can write these out to a unique results file
            # Here I will name the results file with the ROI ID combined with the original result filename
            filename = args.result + "_" + str(i) + ".json" 
            # Save the existing metadata to the new file
            with open(filename, "w") as r:
                r.write(metadata)
            pcv.print_results(filename=filename)
            pcv.outputs.clear()

I would like to combine all the json files in a unique one, which then can be converted in a csv file using json2csv.

I'm trying to apply parallel.process_results but I get a preresult.json file with just {"entities": [], "variables": {}}, which means (as I understood by previous posted issues) no results. All json files are stored in a subdirectory.

Is process_results the right function to use in this case? 

Thank you.


diff --git a/plantcv/parallel/process_results.py b/plantcv/parallel/process_results.py
index c90568c9..912017cd 100644
--- a/plantcv/parallel/process_results.py
+++ b/plantcv/parallel/process_results.py
@@ -40,10 +40,10 @@ def process_results(job_dir, json_file):
                     obs = json.load(results)
                     data["entities"].append(obs)
                     # Keep track of all metadata variables stored
-                    for vars in obs["metadata"].keys():
+                    for vars in obs["metadata"]:
                         data["variables"][vars] = {"category": "metadata", "datatype": "<class 'str'>"}
                     # Keep track of all observations variables stored
-                    for othervars in obs["observations"].keys():
+                    for othervars in obs["observations"]:
                         data["variables"][othervars] = {"category": "observations",
                                                         "datatype": obs["observations"][othervars]["datatype"]}
 
['plantcv/parallel/process_results.py']