Questions tagged [pretty-print]

Prettyprint (or pretty-print) is the application of any of various stylistic formatting conventions to text, source code, markup, and other similar kinds of content. These formatting conventions usually consist of changes in positioning, spacing, color, contrast, size and similar modifications intended to make the content easier for people to view, read and understand.

973 questions
3275
votes
57 answers

How can I pretty-print JSON in a shell script?

Is there a (Unix) shell script to format JSON in human-readable form? Basically, I want it to transform the following: { "foo": "lorem", "bar": "ipsum" } ... into something like this: { "foo": "lorem", "bar": "ipsum" }
AnC
2765
votes
25 answers

pretty-print JSON using JavaScript

How can I display JSON in an easy-to-read (for human readers) format? I'm looking primarily for indentation and whitespace, with perhaps even colors / font-styles / etc.
Mark
  • 57,724
  • 41
  • 114
  • 149
1342
votes
14 answers

How to prettyprint a JSON file?

I have a JSON file that is a mess that I want to prettyprint. What's the easiest way to do this in Python? I know PrettyPrint takes an "object", which I think can be a file, but I don't know how to pass a file in. Just using the filename doesn't…
Colleen
  • 18,089
  • 12
  • 42
  • 70
1120
votes
25 answers

Is there a built-in function to print all the current properties and values of an object?

So what I'm looking for here is something like PHP's print_r function. This is so I can debug my scripts by seeing what's the state of the object in question.
fuentesjr
  • 45,682
  • 27
  • 72
  • 79
673
votes
18 answers

How to "pretty" format JSON output in Ruby on Rails

I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted. Right now, I call to_json and my JSON is all on one line. At times this can be difficult to see if there is a problem in the JSON output stream. Is there way to…
JP Richardson
  • 35,950
  • 34
  • 117
  • 150
654
votes
26 answers

Pretty-Printing JSON with PHP

I'm building a PHP script that feeds JSON data to another script. My script builds data into a large associative array, and then outputs the data using json_encode. Here is an example script: $data = array('a' => 'apple', 'b' => 'banana', 'c' =>…
Zach Rattner
  • 18,673
  • 9
  • 53
  • 79
506
votes
13 answers

How to turn off the Eclipse code formatter for certain sections of Java code?

I've got some Java code with SQL statements written as Java strings (please no OR/M flamewars, the embedded SQL is what it is - not my decision). I've broken the SQL statements semantically into several concatenated strings over several lines of…
Greg Mattes
  • 30,462
  • 13
  • 66
  • 103
465
votes
34 answers

How to pretty print XML from Java?

I have a Java String that contains XML, with no line feeds or indentations. I would like to turn it into a String with nicely formatted XML. How do I do this? String unformattedXml = "hello"; String formattedXml = new…
Steve McLeod
  • 49,211
  • 44
  • 120
  • 177
464
votes
27 answers

Pretty printing XML in Python

What is the best way (or are the various ways) to pretty print XML in Python?
Hortitude
  • 12,632
  • 16
  • 54
  • 71
421
votes
1 answer

Javascript: How to generate formatted easy-to-read JSON straight from an object?

Possible Duplicate: How can I beautify JSON programmatically? I know how to generate JSON from an object using JSON.stringify, or in my case the handy jquery-json from google code (https://github.com/krinkle/jquery-json). Now this works fine,…
Ben Clayton
  • 75,781
  • 25
  • 117
  • 124
397
votes
0 answers

Pretty-print C++ STL containers

I would like to have a single template that once and for all takes care of pretty-printing all STL containers via operator<<. In pseudo code, I'm looking for something like this: template
Kerrek SB
  • 428,875
  • 83
  • 813
  • 1,025
383
votes
2 answers

How can I beautify JSON programmatically?

Do you know of any "JSON Beautifier" for JavaScript? From {"name":"Steve","surname":"Jobs","company":"Apple"} To { "name" : "Steve", "surname" : "Jobs", "company" : "Apple" } Example some_magic(jsonObj); // return beautified JSON
Randy Mayer
  • 6,917
  • 8
  • 22
  • 11
372
votes
14 answers

How to pretty-print a numpy.array without scientific notation and with given precision?

I'm curious, whether there is any way to print formatted numpy.arrays, e.g., in a way similar to this: x = 1.23456 print '%.3f' % x If I want to print the numpy.array of floats, it prints several decimals, often in 'scientific' format, which is…
camillio
  • 3,735
  • 3
  • 14
  • 6
242
votes
18 answers

Pretty-Print JSON in Java

I'm using json-simple and I need to pretty-print JSON data (make it more human readable). I haven't been able to find this functionality within that library. How is this commonly achieved?
mabuzer
  • 5,847
  • 6
  • 32
  • 41
226
votes
12 answers

How can I pretty-print JSON using Go?

Does anyone know of a simple way to pretty-print JSON output in Go? The stock http://golang.org/pkg/encoding/json/ package does not seem to include functionality for this (EDIT: it does, see accepted answer) and a quick google doesn't turn up…
Brad Peabody
  • 8,786
  • 8
  • 36
  • 57
1
2 3
64 65