Problem/Motivation
JSON and XML encoded documents are a pain to read, especially when working with Views to assemble full entity output for a number of different entities. Even objects with relatively simple payloads have sufficient "boilerplate" bracketing to make it very difficult to evaluate the results of a View configuration without saving the view and using the results with the browser plugin or command-line tool of your choice.
Furthermore, non-RESTful development around serialization has a similar problem, and development/troubleshooting of new serializers ubiquitously relies on external tools to make sense of the output.
Proposed resolution
- Option A: Add a contextual option to "pretty-print" serializer output. Serialization done by the Views UI Preview simply sets this argument to TRUE.
- Option B: Take the serialized output and run it through a decode/re-encode process that applies the pretty printing. This opens up options for using more tools, perhaps leaving the mechanism more in the hands of contrib.
As a side-effect, this would facilitate something like a Devel Serialization module which could add preview tabs for entities to see what their serialized output would be in configured formats.
Remaining tasks
- Decide if Core should handle this
- Pick an implementation option
- Code
User interface changes
Views UI Preview becomes readable for REST export data.
API changes
As a dedicated "pretty-printing" service, there would be API additions.
As a contextual parameter for serializers, there would be an additional, minimally documented parameter and a higher impact on Serialization tests.
Data model changes
None.
Comments
Comment #2
dawehnerIs there some nice JS library we could use to pretty print those responses?
Comment #3
Grayside commentedI had initially missed #2499717: Clean up display of JSON+HAL in views preview.
Not sure if they are duplicates, I think I've targeted wider scope here. The approach being taken there for JSON and XML seems to be using "Option B" here, but specifically in the Views Rest Export display code.
The broadest possible interpretation of this issue (especially in light of #2), would be to do something like add https://highlightjs.org/ to Core with some light integration to the serialization system and usage in Views preview.
Comment #5
wim leersPremature abstraction alert. :)
Let's first have an implementation in the sole place where we show serialized data: in the Views UI's preview of REST views.
Then, based on lessons learned, we can consider adding this capability to the Serialization module.
Comment #6
dawehnerI personally don't believe in it. There are tools out there which solve that task much better. Tools like postman solve that problem MUCH better.
Comment #7
wim leersAlright. Then let's communicate that and not let this issue linger.
@dawehner as Views module maintainer thinks this does not make sense in Drupal core right now. Of course, that doesn't mean you can't create a contrib module to do exactly that! :)
Comment #8
nategasser commentedJust a suggestion, since this won't be changed -- the Chrome plugin JSONView (http://goo.gl/ZDLWY0) automatically pretty-prints JSON output. Source is available as well (https://github.com/callumlocke/json-formatter).