2

I'm using Drupal 7 and I've created a content type as 'CONTENT_TABLE', which includes multiple fields (COLUMNS) as such: CONTENT_ID, CONTENT_NAME, LARGE_THUMBNAIL, ZIP_FILE...

I want to export the data (each row of the table) into a JSON. I need to use this JSON as an input for another website.

I have tried to look for Node export module, but I'm not sure how to export the data into JSON which can be used as is.

Expected JSON:

{
   "ContentItems": [
      {
         "CONTENT_ID": "123",
         "CONTENT_NAME": "ABC",
         "LARGE_THUMBNAIL": "C:/LargeThumbnail/ABC.jpg",
         "ZIP_FILE": "C:/LargeThumbnail/ABC.zip"
      },
      {
         "CONTENT_ID": "234",
         "CONTENT_NAME": "PQR",
         "LARGE_THUMBNAIL": "C:/LargeThumbnail/PQR.jpg",
         "ZIP_FILE": "C:/LargeThumbnail/PQR.zip"
      }
   ]
}

2 Answers 2

2

You could make a view of your nodes then use

Views Datasource

Views Datasource is a set of plugins for Drupal Views for rendering content in a number of shareable, reusable formats based on XML, JSON and XHTML.

For how to use, see the accepted answer to this Views JSON output

1
  • I figured this one while searching more thru the Views data export model. Thanks though.
    – Vish
    Commented Feb 5, 2016 at 0:38
4

You could use the Forena module (disclosure: I'm a co-maintainer of it) as your 1-stop-solution (using only 1 contributed module) to:

  • Build your custom query to fetch the data, whereas these data can be retrieved directly from your Drupal database. Obviously, in this case it's be an SQL to retrieve your CONTENT_ID, CONTENT_NAME, LARGE_THUMBNAIL, ZIP_FILE ...

  • Format the look and feel of your results (the report) using xHTML (and/or charts if you'd like).

  • Download the results in any of the typical formats, such as PDF, XLS, CSV, XML, JSON, etc. For any report that you create (using Forena), just add .csv as an extension to the report (output) URL. That contains the CSV equivalent of that report (similar for the other formats).

Example

As a sample, consider the sample report located at /reports/sample.states in your own site (one of the samples shipped with Forena) or in the Simple Table of States in the demo site. Change the URL to /reports/sample.states.csv (= just add .csv to it) to get the same report in .csv format. By adding such .csv to the URL, the result is like so ...

Same technique applies for other supported extensions (export formats), such as:

Remark: when building a report, you can also specify for which of these Document Types an hyperlink should be made available in the report.

Direct access to data blocks

All data blocks are also accessible directly via their url, provided you have permission to access that block. Here are a few samples of that (from the demo site), for the sample report located at /reports/sample.states:

More info

Getting started

  • To actually install/configure Forena, make sure to look at the various steps in the Setup Guide that comes with it, which you can find at /reports/help.setup in your own site also after you enabled Forena (similar to what you can see in the demo site). Missing (forgotten) "permissions" and/or "text formats" configurations (if you don't follow the Setup Guide) or the most common showstoppers if you"re new to Forena ...

  • If you run into "PDO driver support for sqlite not installed", then head over to comment nr 7 in issue #1061436. Here is a summary of it: you only need that for using the "sample database" (the one you can also see in the demo site), which is delivered in SQLite format. So you can use Forena without that support, eg to access your own Drupal database (in MySql fmt). And/or you might want to look at the "drupal admin samples" instead ...

2
  • Thanks Pierre. I'm trying to use the Forena module but when I try to open the 'Structure > Forena Reports' it shows me an error as: "PDO driver support for sqlite not installed" How to resolve it?
    – Vish
    Commented Feb 4, 2016 at 20:44
  • Yes, I completed the setup.
    – Vish
    Commented Feb 4, 2016 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.