This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Add a new attribue type to CubicWeb: Jsonb. This type is mapped to the jsonb PostgreSQL data type.


In your schemas, you can use the new type as follow:

>>> class MyEntityType(EntityType):
...     json_attribute = Jsonb(required=True)


To provide a value for a Jsonb attribute, you can use either:

  • a dict,
  • a JSON string.

For example, you can write the following code:

>>> my_entity.cw_set(json_attribute={'a': [1, 2, 3]})

The code below wil have exactly the same effect:

>>> my_entity.cw_set(json_attribute=u'{"a": [1, 2, 3]}')

Please note that, whatever way you set the value (string or dict), you will always get back a dict when asking for it:

>>> my_entity.json_attribute
{u'a': [1, 2, 3]}


In RQL, you can query a Jsonb attribute in multiple ways. For example, you can ask for attributes containing a specific key/value pair:

>>> import json
>>> rql('Any X WHERE X json_attribute J HAVING JSONB_CONTAINS(J, %(json_value)s)=True',
        {'json_value': json.dumps({u'a': 1})})

You can ask for existence of a specific key:

>>> rql('Any X WHERE X json_attribute J HAVING JSONB_EXISTS(J, %(key)s)=True',
        {'key': u'b'})

You can get the value for a key:

>>> rql('Any JSONB_GET(J, %(key)s) WHERE X json_attribute J, X eid %(eid)s',
        {'key': u'a', 'eid': 1234})

Note: JSONB_GET() will always return a string. If the value is a JSON object (or a JSON array), you may want to use json.loads() afterwards to have a dict (or a list).

One final remark: as the PostgreSQL documentation suggests, you should use the same structure for your JSON data in the same column. This makes querying much easier.

Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
cubicweb-jsonb-0.1.0.tar.gz (9.0 kB) Copy SHA256 Checksum SHA256 Source Nov 24, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting