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.

1047 questions
3609
votes
62 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
3337
votes
31 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
  • 67,098
  • 47
  • 117
  • 162
1872
votes
15 answers

How to prettyprint a JSON file?

How do I pretty-print a JSON file in Python?
Colleen
  • 23,899
  • 12
  • 45
  • 75
1448
votes
31 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
  • 50,920
  • 27
  • 77
  • 81
771
votes
27 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
  • 20,745
  • 9
  • 59
  • 82
746
votes
20 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
  • 38,609
  • 36
  • 119
  • 151
545
votes
1 answer

JavaScript: How can I 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. Now this works fine, but the output is hard to read for humans. …
Ben Clayton
  • 80,996
  • 26
  • 120
  • 129
527
votes
14 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
  • 33,090
  • 15
  • 73
  • 105
526
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
  • 13,638
  • 16
  • 58
  • 72
497
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
  • 51,737
  • 47
  • 128
  • 184
467
votes
1 answer

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
  • 8,455
  • 8
  • 25
  • 11
453
votes
14 answers

Pretty-print a NumPy array without scientific notation and with given precision

How do I print formatted NumPy arrays in a way similar to this: x = 1.23456 print('%.3f' % x) If I want to print the numpy.ndarray of floats, it prints several decimals, often in 'scientific' format, which is rather hard to read even for…
camillio
  • 4,545
  • 3
  • 16
  • 6
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
  • 464,522
  • 92
  • 875
  • 1,084
337
votes
15 answers

How can I pretty-print JSON using Go?

Does anyone know of a simple way to pretty-print JSON output in Go? I'd like to pretty-print the result of json.Marshal, as well as formatting an existing string of JSON so it's easier to read.
Brad Peabody
  • 10,917
  • 9
  • 44
  • 63
288
votes
20 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
  • 6,497
  • 6
  • 35
  • 41
1
2 3
69 70