2

Can anyone tell me how I can get plain JSON output with no surrounding HTML?

I am using the Views and Views JSON modules to get my node data as JSON output.

The problem is my JSON output still comes embedded in the default Drupal theme. I set the default theme to stark hoping that I will not see any HTML in the output but that did not work.

My attempts to set the theme for the View did not work either.

I would appreciate any help. Thanks in advance.

5
  • Go to the configuration of your Views display which produces the JSON output.
  • Click on the Settings link of the JSON data document format.
  • Make sure that Views API mode is not enabled. The description of this setting explains it all:

    Not using View API mode means the JSON gets output directly and the server ceases normal page processing. Using it means the server does not cease processing after outputting the JSON. This allows the Views API to be used with the view without having to prematurely terminate page processing.

0

Try the Views Datasource module. Here is a quote about it (from the module's project page):

... is a set of plugins for Drupal Views for rendering content in a number of shareable, reusable formats based on XML, JSON and XHTML. These formats allow content in a Drupal site to be easily used as data sources for Semantic Web clients and web mash-ups. Views Datasource plugins output content from node lists created in the Drupal Views interface in a variety of formats - XML data documents using schemas like OPML and Atom, RDF data documents using a vocabulary like FOAF, JSON data documents in a format like Exhibit JSON, and XHTML data documents using a microformat like hCard.

Views Datasource can be thought of as a userland complement to the work going on in the Services and RDF APIs as a site operator only needs to know Views to be able to create datasources in the different formats.

The project consists of 4 Views style plugins (and related row plugins):

  • views_xml - Output as raw XML, OPML, and Atom;
  • views_json - Output as Simile/Exhibit JSON, Canonical JSON, JSONP/JSON in script;
  • views_rdf- Output as FOAF, SIOC, and DOAP;
  • views_xhtml - Output as hCard, hCalendar, and Geo.
  • The Views JSON module is shipped with Views Datasource. – balintk Feb 9 '13 at 15:52
  • Ahh, ic. I've never used it myself. – 2pha Feb 9 '13 at 16:28
  • But for D7 it is still in dev and last release date is "2012-Jun-15". – Sivaji Aug 6 '13 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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