[CONTROLLER-477] Add trailing newline to formatted JSON output Created: 14/May/14  Updated: 14/Nov/17  Resolved: 07/Jul/14

Status: Resolved
Project: controller
Component/s: restconf
Affects Version/s: Helium
Fix Version/s: None

Type: Improvement
Reporter: Rob Adams Assignee: Jozef Gloncak
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: Linux
Platform: PC


Issue Links:
Blocks
blocks CONTROLLER-287 Milestone: RESTConf improvements base... Resolved

 Description   

Currently there's no trailing newline to formatted JSON output. This can be annoying when using command-line tools to interact with the REST API.

Though there's also something to be said for not pretty-printing the output by default also since this increases the size of the messages.

Workaround is something like feeding the output into a JSON formatter such as python -mjson.tool.



 Comments   
Comment by Devin Avery [ 29/May/14 ]

I personally would argue that the response should NOT be pretty-printed and it should be up to the receiver to format the results. When you get large, nested outputs, whitespace can add up to be a significant portion of the result.

With that said, we could add a header argument / query param which would optionally pretty-format the result if provided.

==

My proposal - Best of both worlds - by default do NOT pretty-print the output, but allow for either a query param or header value (query param is probably easier) which pretty-prints the response content in the server before return it to the caller.

This will increase usability for developers relying on command line tools etc.

Thoughts?

Comment by Tom Pantelis [ 29/May/14 ]

The RESTCONF draft does define a "format" query parameter:

The "format" parameter is used to specify the format of any content
returned in the response. Note that this parameter MAY be used
instead of the "Accept" header to identify the format desired in the
response.

The "format" parameter is only supported for the GET and HEAD
methods. It is supported for all RESTCONF media types.

syntax: format= xml | json

Although the draft doesn't mention about pretty-printing, we could use "format" to indicate pretty-printed output (as an extension to the draft).

Comment by Rob Adams [ 29/May/14 ]

I'm fine with never pretty-printing or with doing it from a config option in a config file somewhere. I think the bug about formatting errors as JSON is fixed now so the "pipe curl into python -mjson.tool" works just fine.

Comment by Jozef Gloncak [ 25/Jun/14 ]

patch set was proposed
https://git.opendaylight.org/gerrit/#/c/8329

if in URI is specified parameter includeWhiteChars=false then no white characters will be present in JSON|XML output.

if includeWhiteChars is omitted or contains any other value, the white characters will be present in output.

Comment by Jozef Gloncak [ 26/Jun/14 ]

Comment from patch set:
>>>>
Rob Adams
First, it should be called prettyPrint not includeWhiteSpaces.

Second the default should be not to pretty print. So change to prettyPrint=true. The normal operational mode would be to not pretty print, and it's silly to require all calls to the REST API to pass this extra parameter in normal operation.
<<<<

patch set 3 was proposed

  • URI parameter was renamed to prettyPrint
  • behaviour was changed:
  • - if prettyPrint=true - output is pretty printed
  • - other cases - output isn't pretty printed.

https://git.opendaylight.org/gerrit/#/c/8329

Comment by Jozef Gloncak [ 30/Jun/14 ]

patch set 4 was uploaded. parameter of type UriInfo was added to signatures of method which were specified by Devin Avery

Comment by Jozef Gloncak [ 01/Jul/14 ]

patch set which add UriInfo input parameter to once more missing method

Comment by Jozef Gloncak [ 04/Jul/14 ]

patch set 8 which solve conflicts with current master was uploaded.

Generated at Wed Feb 07 19:53:07 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.