I am working on an innovative drupal front end and I need to hook drupal into place to provide me just the content/body of nodes in the form json.

So when a user clicks on the menu, the page does not refresh but grabs the body of the node, so that I can use to re-populate in a sliding container.

How do I, in drupal 7, get a json output of the nodes. I've tried several techniques but I am not having any luck.

"The JSON server module gives you JSON output of nodes. If you want more custom JSON, you can use hook_menu() to create a new menu callback (basically a URL path pointed to a function) and then use drupal_json() within that callback to send the output as JSON rather than the default HTML."

http://stackoverflow.com/questions/3636463/drupal-create-a-page-that-out...

http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_js...

Comments

zeezack’s picture

I tried this, but it looks like its more suited to drupal 5?
http://drupal.org/node/174008

How does one create the menu callback for this to work?
http://drupal4hu.com/node/90

zeezack’s picture



	//_ on navigation  
		$('#nav li a').click(function(event) {
			event.preventDefault();
			
				var link = $(this).attr('href');
				console.log("this link", link);
	
				
				$.getJSON("dajax/node/2/json", function(json){ 
					console.log("the json", json);
					//$('#contentswrapper').empty().html(json.title); 
				});	
              });

I had something like this - where I need to get the contents of the node using something like the above.

zeezack’s picture

zeezack’s picture

This is what I am looking for, but using Drupal 7

http://drupal.org/node/174008#comment-4519778

zeezack’s picture

The first attempt using hook_menu
references:
http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...
http://drupal.org/node/109153
http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_js...
http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...

is it possible to create a custom module like this?

	
	
	//json_generate.info
		; $Id$

		name = Json Generate
		project = "A custom module for Drupla 7 to call a node and return it in json format"
		description = "For use with ajax calls to get the content of a node, without refreshing the page"
		package = "Other"
		version = "7.x"
		core = 7.x	
		
	
	
		//json_generate.module
		<?php
			function json_generate_menu() {
					$items['json_generate/node/%node'] = array(
					'title' => 'json feed', 
					'page callback' => 'json_generate', 
					'access arguments' => array('access content'), 
					'type' => MENU_CALLBACK,
				);
				return $items;
			}

			function json_generate($node) {

			$jsondata = drupal_json_output($node);

			return $jsondata;
		}
		?>
	
	
	//jquery bit
		$('#nav li a').click(function(event) {
			event.preventDefault();

				$.getJSON("json_generate/node/1", function(json){ 
					console.log("the json", json);
					$('#contentswrapper').empty().html(json.title); 
				});

		});	

	
zeezack’s picture

Has anyone got a solution for this? - Is it possible to create a view page that formats the content in json format?

irishgringo’s picture

anyone having any luck here?
pulling json from a view in D7. it is doable in D6 with views_datasource.
but that is all I can find.

Doing Native iPHONE, ANDROID, Titanium, node.js and DRUPAL. as a contractor.

andypanix’s picture

You can find an unofficial D7 port of views_datasource at this address: http://windmill.sk/project/module/views_datasource

I've used it in a recent project and the json module has worked well for what I needed. There is also a specific thread #981810: views_datasource module Drupal 7 port.

Hope this help you.