I used VIews DataSource a lot in D6, but I am trying to use it in D7 and I am running in to this problem.
I get the json that I was looking for, but its inside the content section.
Ideally, I would get just a Downloaded file with a json extention.
So what am I doing wrong?

Comments

arrubiu’s picture

Subscribe..
If I try to use a json output I obtain a "normal" drupal page with the json in the content.

markbrule’s picture

Subscribe.

markbrule’s picture

I went back and read the options more carefully. To get the output without the rest of the page markup, you need to uncheck the "Views API Module" option in the JSON output settings page. That is, when you have set the format to "JSON data document", in the settings panel after setting the "content-type" (to application/json or text/json) uncheck the "Views API Module" checkbox. This is checked by default.

arrubiu’s picture

Ok perfect :)

SeanBannister’s picture

Status: Active » Closed (fixed)
KimmoT’s picture

Status: Closed (fixed) » Active

Attachment views won't work without Views API mode. At least in my case my "main view" is not loaded, but the attachment view is shown and output stops.

Using
Views 7.x-3.7
Views JSON 7.x-1.x-dev

anthonylindsay’s picture

Issue tags: +but why?

Why would you want to use an attachment?

I'm not surprised that an attachment won't work. As far as I understand it, when you uncheck the Views API mode button Drupal ceases normal page processing, like when you call drupal_json_output(). A normal views attachment is a discrete thing from the view to which it is attached. I'd expect that a view that is formatted as json would behave no differently.

So I'd expect that you'd need to put each view on a discrete url and call them separately. If you absolutely need to combine two views into one json object you could create a custom module to implement hook_menu() to create a json endpoint for your output and a custom function to call both views separately and process and combine their output as you require. Then finally call drupal_output_json() to actually send your combined view down the wire.

If you have any control over what is consuming the data, then it would be simplest to deal with two separate calls directly on the page, I think.

KimmoT’s picture

Status: Active » Closed (works as designed)

Basically, I just would have wanted to keep things simple avoiding using hook_menu and all that, but I ended up solving it exactly like you suggested.

So I'm guessing it's safe to call this closed.

joecrespo’s picture

Status: Closed (works as designed) » Active

The UI could use a tweak.

This label is confusing:

[√] Views API mode

  1. The expectation is that checking "API Mode" will put the view in API mode, not embed the view content in the template.
  2. Language could be more clear: "[√] Views API mode (uncheck to render JSON-only)" or just "[√] Embed JSON output in theme"

Changing the language will go a long way toward clarity.

Thanks for the module!

opdavies’s picture

Issue summary: View changes

+1 for #9.

yannickoo’s picture

Status: Active » Closed (duplicate)