Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Given that the only use of JSON output is as a display for feed or web services use, a Page display type isn't really appropriate. That's what the Feed display type is for. The style plugin can and should specify that it works only with Feed displays, which would likely simplify some code and be more in line with what users would expect.
Comments
Comment #1
earthday47+1 agreed. I was confused for about 5-10 minutes, because I automatically went to "Feed" to add the JSON output. I actually thought there was a bug!
Comment #2
thommyboy CreditAttribution: thommyboy commented+1
otherwise one would always need to create a custom template to get rid of all the page-stuff or is there any easy workaround to just get the clean json output?
Comment #3
peterparker CreditAttribution: peterparker commentedI am also looking for a way to get clean json output. The preview when building the view is good, but using view.get returns far too much information.
Can anybody offer a solution?
Comment #4
Alexander Allen CreditAttribution: Alexander Allen commentedHi Peter,
If there is extra information that you need to be removed, fixing this issue won't solve your issue. Issue #1027590 (this issue) is related to how the Views displays are created/categorized (page, block, feed, etc.). Could you please create a separate issue for this and provide more details regarding the extraneous (non-clean) information that json is outputting?
Comment #5
tahiticlic CreditAttribution: tahiticlic commentedSame needs here. I wonder what's the point to have a JSON output in a page... That's in a feed where it should output.
Comment #6
Alexander Allen CreditAttribution: Alexander Allen commentedtahiticlic, let me be the devil's advocate for a second: the current VDS codebase is not flexible enough to allow users to customize the format or the output of the feeds in any way, when not using the drupal templating system. I do agree that this is not the way that this should be working, and that a feed is the way data should be served. If you feel that this is relevant to you, please feel free to subscribe to #1699368: #RVDA: Rewrite Views Datasource's Architecture, and to provide support with testing. This is currently being worked on.
Comment #7
eob CreditAttribution: eob commentedI am trying to configure a JSON view. Using this plugin to do the configuration was easy (thanks!), but when I load the URL, the JSON renders as text inside the HTML page instead of all by itself as a proper JSON document.
What am I doing wrong? How do I just get the JSON? That's the whole point of a JSON feed...
Comment #8
gnugetHi eob.
I found a way to display only the json and not the entire HTML page.
just edit your view and uncheck the "Views api mode" in the settings of "Json data document" now you will only see the json feed instead the entire site.
Comment #9
davidneedham+1 agree it should use feed display rather than page.
@gnuget Thanks for the suggestion to uncheck the "views api mode" box. That fixed my original reason for visiting the queue!
Comment #10
IKE0088 CreditAttribution: IKE0088 commentedWhen I uncheck views api mode, and attempt to visit the page, it attempts to include the output to a file to be saved on my desktop. Any ideas as to why it would do this? It is doing the same with Views GeoJSON module.
Comment #11
IKE0088 CreditAttribution: IKE0088 commentedAppears to happen on IE8. Chrome works fine...
Comment #12
anthonylindsay CreditAttribution: anthonylindsay commentedI read on StackOverflow that it's a known issue with IE8 that it doesn't play nice with application/json and you need to send it down the wire as text. There's a setting in the JSON format page style options on your view where you can choose whether to send it as application or text.
Comment #13
owntheweb CreditAttribution: owntheweb commented#8: gnuget: Thank you. :)
Comment #14
yannickooHey guys, it's documented in the README.txt :)
Comment #15
Crell CreditAttribution: Crell commentedyannickoo: That's nice. That's still the Wrong Way To Do It(tm) in Drupal 7. :-) Feed displays exist for this reason. Use 'em.
Comment #16
yannickooOh, Crell replied me :o I guess that this issue cannot be solved in the 1.x branch of this module because it is a major update but if there is some time I will give my best to correct that part!
Comment #17
ZeiP CreditAttribution: ZeiP as a volunteer commented