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.
Hi, I need to change the JSON output from the actual:
{
"nodes":[
{"id":"7081" .....
to
{
"status": "OK",
"num_results": 10,
"nodes":[
{"id":"7081" .....
Someone can help me, I read the code but i dont'understand enough :(. How can I get these two lines?
Thanks
Comments
Comment #1
Alexander Allen CreditAttribution: Alexander Allen commentedHi Aress,
Neither nesting, nor top-level document properties are currently supported by views_datasource. In your example, "status" and "num_results" could be properties that belong to the JSON document itself. The most obvious way that I see this could be accomplished is by adding variables into the header settings for the View. I have tried doing that already, only to come across this exact same issue. Header variables are ignored by this module. As a result, I ended up using relationships to node reference fields, resulting in duplicate items like so:
My approach is only a temporary workaround (otherwise I would need to ditch views_datasource altogether). This needs to be fixed, urgently. It is frustrating for front-end developers to have to deal with the duplicated fields, and considering this module is used a lot for serving feeds into mobile devices, it also increases significantly the feeds' size on the wire.
Changed to task -> major.
Assigned to myself, as default. If anyone else wants to give a hand w/ this let me know.
Comment #2
Alexander Allen CreditAttribution: Alexander Allen commentedComment #3
Alexander Allen CreditAttribution: Alexander Allen commentedTagging and bumping priority. This is a major part of #RVDA.
Comment #4
elephant.jim CreditAttribution: elephant.jim commentedI ran into this same problem. I wanted to use a views pager to limit the results returned, but still report the total count. The easy way is to add the "Global: Results summary" to the view header. But then that needs to get stuffed into the JSON ...
The patch I used for simple JSON output was:
You'd also need to change template_preprocess_views_views_json_style_exhibit and template_preprocess_views_views_json_style_jqgrid to match template_preprocess_views_views_json_style_simple.
Comment #5
kenorb CreditAttribution: kenorb commentedComment #6
kenorb CreditAttribution: kenorb commentedComment #7
ZeiP CreditAttribution: ZeiP as a volunteer commented