Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand correctly, you're just looking to filter the end result here? If you haven't already, go ahead and convert the json string to a python object</p> <pre><code>import json resp = json.loads(fql_resp) data = resp['data'] </code></pre> <p>The <code>loads</code> stands for <em>load string</em> which is what you'll be getting back from the service. From here you have a few options. One choice is to use the builtin <code>filter</code> if you know before hand what categories you want. Take for example the following data set</p> <pre><code>objs = [{'_id': 1, 'categories': ['a', 'b', 'c']}, {'_id': 2, 'categories': ['b']}, {'_id': 3, 'categories': ['c']}] </code></pre> <p>You could filter results that only contain the <code>b</code> category like so</p> <pre><code>def f(obj): return 'b' in obj['categories'] filtered_objs = filter(f, objs) print(filtered_objs) # outputs: # [{'_id': 1, 'categories': ['a', 'b', 'c']}, # {'_id': 2, 'categories': ['b']}] </code></pre> <p>if you want a reusable function to filter for different categories you could do something like</p> <pre><code>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') </code></pre> <p>And lastly, you could just use a list comprehension, either inline as needed or in the filter_objs function.</p> <pre><code>filtered_objs = [obj for obj in objs if 'b' in obj['categories']] </code></pre> <p>So there's a number of ways to filter the result, but the first step is to use <code>json.loads</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload