How do I render a node queue as custom JSON? What would be the most sensible way to render a nodequeue queue in a custom JSON format (using Drupal 6)

We have a nodequeue that is both included in the UI in various places and served in a RSS feed.

I've found that I can use drupal_json() to convert a PHP data structure to JSON so now I'm mostly after what would be the right place for this?

As a hack, I tried to use RSS feed and to have a custom template for the feed. My problem there is that a) it feels pretty hackish and b) in the "general template" available I don't have the content available.

(As background, I'm pretty new with Drupal so the answer here is probably pretty straight-forward)

Where to continue?
There are some Views JSON modules if you look around, but I typically do this outside of views itself.  And you are correct, you are halfway there.

You want to wire up a hook_menu() to create a custom path in a module.  See our canonical question on this topic for more information.

Then in the menu callback, you do use views_embed_view().  Something like this:

function MYMODULE_the_callback() {
  $output = views_embed_view('nodequeue_1', 'the_display');

  print drupal_json($output);
  exit;
}


You can also use the $view object directly:

function MYMODULE_the_callback() {
  $view = views_get_view('nodequeue_1');
  $view-&gt;set_display('the_display');
  $view-&gt;pre_execute();
  $view-&gt;execute();

  $output = $view-&gt;render();

  print drupal_json($output);
  exit;
}


Using the later form, you can poke through the $view object and tailor your JSON accordingly.

This should give you a head start.

Keep in mind as you research this, that the plumbing is a little different for rendering JSON in Drupal 6 vs 7.  In 7, you would use drupal_json_output() and drupal_exit();