This module provides 1 root element, which contains reach Views row as immediate children. However, In my experience, API's that wrap data in some sort of envelope, which also provide separate root elements for result data and metadata, are much easier to use. Examples can be seen in http://jsonapi.org/examples/. This is a request to support such arrangements.

If there is a way to configure this, let me know, but I don't see how this can be done through configuration alone.

Some notes:

  • Header/footer elements seem like a good option as they allow for token replacement with result data by default (e.g. @total), however, these seem to get ignored for now, or are output outside of the data structure within the Views preview.
  • views_json might be more ready for this than the XML module. As the json is already output with a single root object that has a property for "nodes" or whatever you want by default. While the XML response uses a root element named "nodes". This is an assumption based on just looking at how these modules output their data.

There are similar issues in this module's queue that touch on this idea:

Of course, if this were to be implemented, then it can't be the default option (or would need to go into a new, major release) as altering the way data is structure would break so many people's implementations.

Implementation approaches: use the header route, make a setting in the display mode form for data/metadata envelopes?

Comments

bburg created an issue.