If I understand correctly, you just want to filter the final result here? If you haven't done it yet, go ahead and convert the json string to a python object
import json resp = json.loads(fql_resp) data = resp['data']
loads indicates the load line you will receive from the service. From here you have several options. One option is to use the built-in filter if you know in front of you which categories you want. Take for example the following dataset
objs = [{'_id': 1, 'categories': ['a', 'b', 'c']}, {'_id': 2, 'categories': ['b']}, {'_id': 3, 'categories': ['c']}]
You can filter results that contain only category b , for example
def f(obj): return 'b' in obj['categories'] filtered_objs = filter(f, objs) print(filtered_objs)
If you want the reuse function to filter for different categories, you can do something like
def filter_objs(objs, category): result = [] for obj in objs: if category in obj['categories']: result.append(category) return result filtered_objs = filter_objs(objs, 'b')
And finally, you could just use list comprehension, whether built in as needed or in the filter_objs function.
filtered_objs = [obj for obj in objs if 'b' in obj['categories']]
Thus, there are several ways to filter the result, but the first step is to use json.loads