Skip to content

A NodeJS command line utility to pretty print JSON string like an object literal to the terminal with color.

License

Notifications You must be signed in to change notification settings

Cerlancism/pretty-color-json-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pretty-color-json-cli

A NodeJS command line utility to pretty print JSON string like an object literal with color to the terminal using the native console.log and inspect from NodeJS.

Similar tools:

Installation

# npm install -g https://github.com/Cerlancism/pretty-color-json-cli

Examples

Piping

$ curl -sL https://ipinfo.io/1.1.1.1/json | pretty-color-json

{
  ip: '1.1.1.1',
  hostname: 'one.one.one.one',
  city: 'The Rocks',
  region: 'New South Wales',
  country: 'AU',
  loc: '-33.8592,151.2081',
  org: 'AS13335 Cloudflare, Inc.',
  postal: '2000',
  timezone: 'Australia/Sydney',
  readme: 'https://ipinfo.io/missingauth'
}

Read from file

$ curl -sL https://api.chucknorris.io/jokes/random > joke.json

joke.json:

{"category":null,"icon_url":"https:\/\/assets.chucknorris.host\/img\/avatar\/chuck-norris.png","id":"zvno1ZJIQfetnTX5ye8TwQ","url":"https:\/\/api.chucknorris.io\/jokes\/zvno1ZJIQfetnTX5ye8TwQ","value":"The Old Spice Man aspires to smell like Chuck Norris"}

$ pretty-color-json < joke.json

{
  categories: [],
  created_at: '2020-01-05 13:42:26.991637',
  icon_url: 'https://assets.chucknorris.host/img/avatar/chuck-norris.png',
  id: 'A7jUZR5wTZGvV-jtyIphOw',
  updated_at: '2020-01-05 13:42:26.991637',
  url: 'https://api.chucknorris.io/jokes/A7jUZR5wTZGvV-jtyIphOw',
  value: 'Chuck Norris once ran a quarter mile in 3.7 seconds, while pulling an 18-wheeler in wet cement.'
}

Output as a formatted JSON file

$ pretty-color-json < joke.json > joke_formatted.json

{
  "categories": [],
  "created_at": "2020-01-05 13:42:26.991637",
  "icon_url": "https://assets.chucknorris.host/img/avatar/chuck-norris.png",
  "id": "A7jUZR5wTZGvV-jtyIphOw",
  "updated_at": "2020-01-05 13:42:26.991637",
  "url": "https://api.chucknorris.io/jokes/A7jUZR5wTZGvV-jtyIphOw",
  "value": "Chuck Norris once ran a quarter mile in 3.7 seconds, while pulling an 18-wheeler in wet cement."
}

Note

This by default prints JSON like a JavaScript object literal which the keys are no longer wrapped with quotes, therefore the output will no longer be a valid JSON. Use json-format-cli or output to a file instead for formatted valid JSON.

About

A NodeJS command line utility to pretty print JSON string like an object literal to the terminal with color.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages