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

Grayside created an issue. See original summary.

dawehner’s picture

Is there some nice JS library we could use to pretty print those responses?

Grayside’s picture

I 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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Title: Create a facility to pretty-print serialized data and use in Views preview » REST views: Create a facility to pretty-print serialized data and use in Views UI preview
Component: serialization.module » views_ui.module
Issue tags: -REST +API-First Initiative

Premature 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.

dawehner’s picture

I 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.

wim leers’s picture

Status: Active » Closed (works as designed)

Alright. 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! :)

nategasser’s picture

Just 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).