Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 135 lines (91 sloc) 3.583 kb
e0eed8d @rafeca Add code coverage badge
authored
1 # prettyjson [![Build Status](https://secure.travis-ci.org/rafeca/prettyjson.png)](http://travis-ci.org/rafeca/prettyjson) [![NPM version](https://badge.fury.io/js/prettyjson.png)](http://badge.fury.io/js/prettyjson) [![Coverage Status](https://coveralls.io/repos/rafeca/prettyjson/badge.png?branch=master)](https://coveralls.io/r/rafeca/prettyjson?branch=master)
2f14e34 @rafeca Initial commit
authored
2
755817c @rafeca Random commit
authored
3 Package for formatting JSON data in a coloured YAML-style, perfect for CLI output.
2f14e34 @rafeca Initial commit
authored
4
5 ## How to install
6
06a9374 @rafeca Add link to coverage html file to README.md
authored
7 Just install it via NPM:
970e4fa @rafeca Minor improvements in README file
authored
8
9 ```bash
5a413d6 @rafeca Update readme to fix #12
authored
10 $ npm install -g prettyjson
970e4fa @rafeca Minor improvements in README file
authored
11 ```
2f14e34 @rafeca Initial commit
authored
12
5a413d6 @rafeca Update readme to fix #12
authored
13 This will install `prettyjson` globally, so it will be added automatically
14 to your `PATH`.
15
682cd21 @rafeca Added CLI interface
authored
16 ## Using it (from the CLI)
17
7b720e7 @rafeca Update Readme and add deprecation notice
authored
18 This package installs a command line interface to render JSON data in a more
19 convenient way. You can use the CLI in three different ways:
682cd21 @rafeca Added CLI interface
authored
20
7b720e7 @rafeca Update Readme and add deprecation notice
authored
21 **Decode a JSON file:** If you want to see the contents of a JSON file, just pass
22 it as the first argument to the CLI:
970e4fa @rafeca Minor improvements in README file
authored
23
24 ```bash
25 $ prettyjson package.json
26 ```
682cd21 @rafeca Added CLI interface
authored
27
e6f6eea @rafeca Fix images in Readme when displayed in npmjs.org
authored
28 ![Example 1](https://raw.github.com/rafeca/prettyjson/master/images/example3.png)
682cd21 @rafeca Added CLI interface
authored
29
7b720e7 @rafeca Update Readme and add deprecation notice
authored
30 **Decode the stdin:** You can also pipe the result of a command (for example an
31 HTTP request) to the CLI to see the JSON result in a clearer way:
970e4fa @rafeca Minor improvements in README file
authored
32
33 ```bash
34 $ curl https://api.github.com/users/rafeca | prettyjson
35 ```
682cd21 @rafeca Added CLI interface
authored
36
e6f6eea @rafeca Fix images in Readme when displayed in npmjs.org
authored
37 ![Example 2](https://raw.github.com/rafeca/prettyjson/master/images/example4.png)
682cd21 @rafeca Added CLI interface
authored
38
7b720e7 @rafeca Update Readme and add deprecation notice
authored
39 **Decode random strings:** if you call the CLI with no arguments, you'll get a
40 prompt where you can past JSON strings and they'll be automatically displayed in a clearer way:
682cd21 @rafeca Added CLI interface
authored
41
e6f6eea @rafeca Fix images in Readme when displayed in npmjs.org
authored
42 ![Example 3](https://raw.github.com/rafeca/prettyjson/master/images/example5.png)
682cd21 @rafeca Added CLI interface
authored
43
7b720e7 @rafeca Update Readme and add deprecation notice
authored
44 ### Command line options
dbcda15 @rafeca Update Readme file with info about env vars
authored
45
7b720e7 @rafeca Update Readme and add deprecation notice
authored
46 It's possible to customize the output through some command line options:
dbcda15 @rafeca Update Readme file with info about env vars
authored
47
48 ```bash
7b720e7 @rafeca Update Readme and add deprecation notice
authored
49 # Change colors
50 $ prettyjson --string=red --keys=blue --dash=yellow --number=green package.json
51
52 # Do not use colors
53 $ prettyjson --nocolor=1 package.json
54
55 # Change indentation
56 $ prettyjson --indent=4 package.json
4141fae @rafeca Update Readme
authored
57
58 # Render arrays elements in a single line
59 $ prettyjson --inline-arrays=1 package.json
dbcda15 @rafeca Update Readme file with info about env vars
authored
60 ```
61
7b720e7 @rafeca Update Readme and add deprecation notice
authored
62 **Deprecation Notice**: The old configuration through environment variables is
63 deprecated and it will be removed in the next major version (1.0.0).
dbcda15 @rafeca Update Readme file with info about env vars
authored
64
682cd21 @rafeca Added CLI interface
authored
65 ## Using it (from Node.js)
2f14e34 @rafeca Initial commit
authored
66
7b720e7 @rafeca Update Readme and add deprecation notice
authored
67 It's pretty easy to use it. You just have to include it in your script and call
68 the `render()` method:
970e4fa @rafeca Minor improvements in README file
authored
69
70 ```javascript
71 var prettyjson = require('prettyjson');
8a8808c @rafeca Minor fix to Readme
authored
72
970e4fa @rafeca Minor improvements in README file
authored
73 var data = {
74 username: 'rafeca',
75 url: 'https://github.com/rafeca',
76 twitter_account: 'https://twitter.com/rafeca',
77 projects: ['prettyprint', 'connfu']
78 };
79
7b720e7 @rafeca Update Readme and add deprecation notice
authored
80 var options = {
ef74b34 @alexey-detr Fixed wrong parameter name to disable coloring option.
alexey-detr authored
81 noColor: true
7b720e7 @rafeca Update Readme and add deprecation notice
authored
82 };
83
84 console.log(prettyjson.render(data, options));
970e4fa @rafeca Minor improvements in README file
authored
85 ```
2f14e34 @rafeca Initial commit
authored
86
87 And will output:
8a8808c @rafeca Minor fix to Readme
authored
88
e6f6eea @rafeca Fix images in Readme when displayed in npmjs.org
authored
89 ![Example 4](https://raw.github.com/rafeca/prettyjson/master/images/example1.png)
2f14e34 @rafeca Initial commit
authored
90
91 You can also configure the colors of the hash keys and array dashes
92 (using [colors.js](https://github.com/Marak/colors.js) colors syntax):
93
970e4fa @rafeca Minor improvements in README file
authored
94 ```javascript
95 var prettyjson = require('prettyjson');
96
97 var data = {
98 username: 'rafeca',
99 url: 'https://github.com/rafeca',
100 twitter_account: 'https://twitter.com/rafeca',
101 projects: ['prettyprint', 'connfu']
102 };
2f14e34 @rafeca Initial commit
authored
103
970e4fa @rafeca Minor improvements in README file
authored
104 console.log(prettyjson.render(data, {
8a8808c @rafeca Minor fix to Readme
authored
105 keysColor: 'rainbow',
499693c @jiyinyiyong Update Readme
jiyinyiyong authored
106 dashColor: 'magenta',
8a8808c @rafeca Minor fix to Readme
authored
107 stringColor: 'white'
970e4fa @rafeca Minor improvements in README file
authored
108 }));
109 ```
2f14e34 @rafeca Initial commit
authored
110
111 Will output something like:
112
e6f6eea @rafeca Fix images in Readme when displayed in npmjs.org
authored
113 ![Example 5](https://raw.github.com/rafeca/prettyjson/master/images/example2.png)
2f14e34 @rafeca Initial commit
authored
114
115 ## Running Tests
116
7b720e7 @rafeca Update Readme and add deprecation notice
authored
117 To run the test suite first invoke the following command within the repo,
118 installing the development dependencies:
970e4fa @rafeca Minor improvements in README file
authored
119
120 ```bash
40673af @rafeca Simplify the release process
authored
121 $ npm install
970e4fa @rafeca Minor improvements in README file
authored
122 ```
2f14e34 @rafeca Initial commit
authored
123
124 then run the tests:
970e4fa @rafeca Minor improvements in README file
authored
125
126 ```bash
127 $ npm test
128 ```
2f14e34 @rafeca Initial commit
authored
129
c77cec7 @shaunmccarthy Made tests work on Windows also
shaunmccarthy authored
130 On windows, you can run the tests with:
131
132 ```cmd
133 C:\git\prettyjson> npm run-script testwin
134 ```
Something went wrong with that request. Please try again.