Bug #8194

Faces should pretty-print json

Added by Luke Kanies almost 2 years ago. Updated almost 2 years ago.

Status:AcceptedStart date:07/01/2011
Priority:HighDue date:
Assignee:-% Done:

0%

Category:usability
Target version:-
Affected Puppet version: Branch:
Keywords:usability

Description

We currently print json in its most dense form, which makes it basically useless for human consumption:

{"data":{"edges":[{"target":"File[/tmp/foo]","source":"Class[main]"},{"target":"Class[main]","source":"Stage[main]"}],"name":"localhost","resources":[{"exported":false,"line":84,"title":"/tmp/foo","parameters":{"content":"meh","ensure":"present"},"tags":["file","class"],"type":"File","file":"/Users/luke/bin/test.pp"},{"exported":false,"title":"main","parameters":{"name":"main"},"tags":["stage"],"type":"Stage"},{"exported":false,"title":"Settings","tags":["class","settings"],"type":"Class"},{"exported":false,"title":"main","parameters":{"name":"main"},"tags":["class"],"type":"Class"}],"tags":["settings"],"classes":["settings"],"version":1309539501},"metadata":{"api_version":1},"document_type":"Catalog"}

We should convert all of these to pretty-printed forms.


Related issues

Related to Puppet - Bug #16172: JSON should be pretty-printed when serialized to disk Re-opened 08/29/2012

History

#1 Updated by Daniel Pittman almost 2 years ago

So, this is tied to the network format handling system, which defaults to the dense rendering. If you ask for JSON format, it would take extra custom code that did the same work as the existing JSON rendering in the NF code, or that reformatted the JSON it got back, neither of which seem ideal.

If you just wanted this in the :console format, that wouldn’t be so bad, but still requires some custom code.

OTOH, if we change the default format in the NF code to be pretty-printed, it doesn’t much change the equation for machines, but does help humans…

#2 Updated by Jeff McCune almost 2 years ago

Just out of curiosity, why is this marked as priority high?

-Jeff

#3 Updated by Luke Kanies almost 2 years ago

Jeff McCune wrote:

Just out of curiosity, why is this marked as priority high?

I marked it as high priority because json output is about 1/10 as useful without it. With this bug fixed, you can directly see something on the console; without it, you constantly have to transform it into a readable form.

#4 Updated by Luke Kanies almost 2 years ago

Daniel Pittman wrote:

So, this is tied to the network format handling system, which defaults to the dense rendering. If you ask for JSON format, it would take extra custom code that did the same work as the existing JSON rendering in the NF code, or that reformatted the JSON it got back, neither of which seem ideal.

If you just wanted this in the :console format, that wouldn’t be so bad, but still requires some custom code.

OTOH, if we change the default format in the NF code to be pretty-printed, it doesn’t much change the equation for machines, but does help humans…

I’d prefer to pay the cost of the extra characters in all versions than not have this, that’s for sure.

In looking at the code, though, all you really need to do is a small amount of special-casing of json. Something like changing this:

  def render(result)
    # Invoke the rendering hook supplied by the user, if appropriate.
    if hook = action.when_rendering(render_as.name)
      result = hook.call(result)
    end

    render_as.render(result)
  end

to this:

  def render(result)
    # Invoke the rendering hook supplied by the user, if appropriate.
    if hook = action.when_rendering(render_as.name)
      result = hook.call(result)
    end

    if render_as.name == :pson
      jj result
    else
      render_as.render(result)
    end
  end

This is what my first version of faces did, I think.

Also available in: Atom PDF