This project is not covered by Drupal’s security advisory policy.

This module implements a Drupal field type that stores JSON or JSONB data.

Database versions that support JSON/JSONB

Why?

This module began as a means of storing a lot of data in JSON, without the data column being a serialized blob. NoSQL stores like MongoDB could not be utilized, but databases now have a JSON/JSONB data type that was designed for this purpose. That means you can store data the Drupal way, in one database. The data can be stored as-is, just like a schema-less NoSQL store.

Some of the perks with the JSON/JSONB data type relate to performance, and JSONB properties can be indexed. Developers can use this module to implement fields that store large amounts of data, that are queryable as one record. Here is an example:

Given an array of JSON objects, stored in a JSONB field on a content type:

[
  {
    "DataType":"Percent",
    "FIPS":"01",
    "Area":"Alabama",
    "Data":"0.833219",
    "TimeFrame":"2003-2004",
    "Education":"Total"
  },
  {
    "DataType":"Percent",
    "FIPS":"01",
    "Area":"Alabama",
    "Data":"0.849364",
    "TimeFrame":"2003-2004",
    "Education":"Bachelor's degree or higher"
  },
  {
    "DataType":"Percent",
    "FIPS":"01",
    "Area":"Alabama",
    "Data":"0.828647",
    "TimeFrame":"2003-2004",
    "Education":"High school graduate"
  },
  {
    "DataType":"Percent",
    "FIPS":"01",
    "Area":"Alabama",
    "Data":"0.858647",
    "TimeFrame":"2005-2006",
    "Education":"High school graduate"
  }
]

If you wanted to query for JSON records that were in the 2005-2006 timeframe for high school graduates, you could do the following:

$results = db_query("SELECT point
      FROM (SELECT jsonb_array_elements(field_jsondata_value) point FROM {node__field_jsondata}) points
      WHERE point->'DataType' = :type
        AND point->'TimeFrame' = :frame
        AND point->'Education' = :education",
      array(':type' => '"Percent"', ':frame' => '"2005-2006"', ':education' => '"High school graduate"'));

You would receive the fourth object only. The function jsonb_array_elements expands data at runtime to query data in this manner. This would not be possible as a serialized blob of data. You would not need to create Drupal fields for every data point, nor write queries that would require all the joining of fields (resulting in a performance hit). Other functions are also available to you to use.

Futher information relating to these data types:

Supporting organizations: 
Developed and sponsored by

Project Information

Downloads