how can i filter a json file based on another json in python?

I’m not sure if it works

class my_input:

    def __init__(self,my_request, my_array):
        self.my_request = my_request
        self.my_array = my_array

    def get_places(self):
        return self.my_request['data']['place']

    def get_traits(self):
        return self.my_request['data']['trait']

    def get_associated_plots(self,places):
        associated_plots = []
        place_st = set(places)
        for current_data in self.my_array['data']['measurementArray']['locationArray']['data']:
            if str(current_data[0]) in place_st:
                associated_plots.append(current_data[1])
        return associated_plots

    def get_rows(self,associated_plots,traits):
        triats_st = set(traits)
        associated_plots_st = set(associated_plots)

        for current_data in self.my_array['data']['measurementArray']['data']:
            rows = []
            if current_data[0] in associated_plots_st and str(current_data[1]) in triats_st:
                rows.append(current_data)
        return rows


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top