Score:1

How do I implement a JSON/JSONB data type field to display data as separate columuns?

vn flag

I have a custom table that consists of 2 columns, id and data. I want to create a view table with filter. The table columns should be id, product, and item. product and item are from the data column which contains JSON data (for example {"product": "a", "item": "b"}).

Is it possible to create this type of view?

As per my knowledge, it's not possible to create because a view works with columns that exist in the database table.

cn flag
Which module are you using for JSON field support?
Lokesh1024 avatar
vn flag
@PatrickKenny No, I'm not using any module for the JSON field. it's a custom table with the Datatype of JSON.
Score:1
in flag

JSONB is Postgres only but Drupal can create JSON field storage types for MySQL too. There are modules that can do both. However, Views support will be light until the additional query functions for JSON are supported. But, you can write the queries yourself in code and it will work.

As for getting Views to query custom tables, this is possible if you describe your data to Views using its API hook(s).

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.