parsing in couchdbkit

186 Views Asked by At

The data retrieved from couchdb is the following:

{'value': 'UMMC', 'id': 'ef688c440131f59262f2c4f80d001c87', 'key': 'ef688c440131f59262f2c4f80d001c87'}
{'value': 'test', 'id': 'fc2c556010c5167c4a32a7ea4d001d8b', 'key': 'fc2c556010c5167c4a32a7ea4d001d8b'}
{'value': 'Travis', 'id': 'fc2c556010c5167c4a32a7ea4d02889d', 'key': 'fc2c556010c5167c4a32a7ea4d02889d'}
{'value': 'testing', 'id': 'fc2c556010c5167c4a32a7ea4d02b3f8', 'key': 'fc2c556010c5167c4a32a7ea4d02b3f8'}

and I am using the following code to extract data

projects = db.view('projects/name')

My question is: Any way I can parse that output so as to have only test, UMMC, Travis, testing

I looked at the viewresults object from couchdbkit documentation but did not find any helpful attributes or functions that I can help parse that output. I wonder what's out there that I can use. Thanks

2

There are 2 best solutions below

0
On

Thanks every one for the help.

In my views.py I had the following:

projects = db.view('projects/name')

and I was trying to display the content of the 'value' attribute in my django template base_site.html

{'value': 'UMMC', 'id': 'ef688c440131f59262f2c4f80d001c87', 'key': 'ef688c440131f59262f2c4f80d001c87'}

so I did:

{%for p in projects%}
   <td>{{p.value }} </td>
{% endfor %}

And it displayed exactly the content of 'value' attribute, Again thanks so much, your feedback really guided me.

1
On

Use the json module, ex:

import json
obj = json.loads("{'value': 'UMMC', 'id': 'ef688c440131f59262f2c4f80d001c87', 'key': 'ef688c440131f59262f2c4f80d001c87'}")
# now obj["value"] == "UMMC";