:sparkles: Make your JSON look AWESOME

Overview

Make your JSON objects look AWESOME!

Jsome Jsome Jsome

Downloads stats

Jsome

This package allows you to give style to your JSON on your console!

Installation :

  $ npm install jsome

if you need to use jsome as a command line, you may need to instal it globally

  $ [sudo] npm install -g jsome

How does it work ?

Command line :

Using jsome as a command line, you need to run the following command that takes the path to your json file as argument

  $ jsome /path/to/your/json/file.json
  $ jsome [options] /path/to/your/json/file.json

You can also send a json string through a pipe (|)

  $ cat /path/to/your/json/file.json | jsome

The options available are :

  • -c: to enable or disable colors (defualt value: true)
  • -l: to enable or disable levels (default value: false)
  • -s: to specify the number of tabulation spaces (default value: 2)
  • -r: to specify valid JSON as output (default value: true)

examples :

  $ jsome -c false /path/to/your/file.json
  $ jsome -c false -l true /path/to/your/file.json
  $ jsome -s 4 /path/to/your/file.json
Module :

On your nodejs application, when you need to console.log a json object, all you need to do is to use the jsome function

    var jsome = require('jsome');
    jsome([{"id":1,"email":"[email protected]","active":true},{"id":2,"email":"[email protected]","active":false},{"id":3,"email":"[email protected]","active":true}]);

Then your json object will be displayed on the console in a pretty format with Awsome colors ! Here is the result :

jsome

The jsome function returns the object passed as argument so that when debugging, you can print the value of an object without having to change a lot on your code

    // instead of 
    
    var foo = {
      bar : obj
    }
    jsome (obj);
    
    // you can do this :
    
    var foo = {
      bar : jsome(obj)
    }
    

You can add some points to show levels of elements... very helpful when you are dealing with complex json objects

    jsome.level.show = true;

jsome

The object jsome.level has as default value the following json :

  jsome.level = {
      'show'    : false
    , 'char'    : '.'
    , 'color'   : 'red'
    , 'spaces'  : 2
    , 'start'   : 0
  }

You can change the level char, its color ( see chalk package ) and the number of spaces for each level.

You can also display your json starting from a specific level to avoid displaying your json starting from the extreme left. You can do that by changing the value jsome.level.start.

You can configure the colors of the displayed json by changing the values of the jsome.colors object which has as default these values.

  jsome.colors = {
      'num'   : 'cyan'    // stands for numbers
    , 'str'   : 'magenta' // stands for strings
    , 'bool'  : 'red'     // stands for booleans
    , 'regex' : 'blue'    // stands for regular expressions
    , 'undef' : 'grey'    // stands for undefined
    , 'null'  : 'grey'    // stands for null
    , 'attr'  : 'green'   // objects attributes -> { attr : value }
    , 'quot'  : 'yellow'  // strings quotes -> "..."
    , 'punc'  : 'yellow'  // commas seperating arrays and objects values -> [ , , , ]
    , 'brack' : 'yellow'  // for both {} and []
  }

You can not only use the color value as string but also you can use an array to specify the background color or you can make things look bold ( see chalk package for more details )

  jsome.colors.bool  = ['green' , 'bgRed']
  jsome.colors.attr  = ['green' , 'bold']
  jsome.colors.quot  = ['yellow', 'bold']
  jsome.colors.punc  = ['yellow', 'bold']
  jsome.colors.brack = ['yellow', 'bold']

jsome

When you have a json as a string, instead of passing by JSON.parse function, you can just call the parse function of jsome

  jsome(JSON.parse('[1,2,3]'));

becomes:

  jsome.parse('[1,2,3]');

If you need to disable the colors:

  jsome.params.colored = false;

If you need JSON which pases linting:

  jsome.params.lintable = true;

When you have a very long json to display, don't make your code blocking... you can enable the asynchronous mode.

  jsome.params.async = true;

  jsome(longJson, function () {
      /* Your code here */
  });

The default value of params is:

  jsome.params = {
      'colored' : true
    , 'async'   : false
    , 'lintable': false
  }

In order to get the colored string without printing it on the console :

   var coloredString = jsome.getColoredString(obj)
Comments
  • jsome-cli

    jsome-cli

    I have tried to make a cli to this package to allow the user to print json files directly on the console using a command line, example :

     $ jsome /path/to/file.json
    

    I have added the bin property on the package.json here, it points to this file

    The issue I have is that after installing the package globally it works on Windows, but not on Linux, I haven't tried it on a Mac OS though. can someone help me with this issue ?

    bug 
    opened by Javascipt 26
  • jsome.level.show=true displaying

    jsome.level.show=true displaying "undefined" instead of level.char

    First of all, AWESOME work here!!! :+1: Love your code and style. I am that guy who duplicated this precious gem with json-colorz. I hope you take that as an honor.

    In testing this latest version, came across a situation with the following setup:

    var obj = {
      a: 1,
      b: 2,
      c: {
        d: {
          e: 3
        }
      }
    }
    
    jsome.level.show = true
    jsome.level.spaces = 2
    jsome.level.start = 2
    
    jsome(obj)
    

    which displays:

    undefined undefined {
    undefined undefined undefined a: 1,
    undefined undefined undefined b: 2,
    undefined undefined undefined c: {
    undefined undefined undefined undefined d: {
    undefined undefined undefined undefined undefined e: 3
    undefined undefined undefined undefined }
    undefined undefined undefined }
    undefined undefined }
    

    I think the problem originates from this line

    maybe you wish to do something like the following...

    levelStr = levelStr.replace(' ', useColorProvider(opts.char, opts.color))
    

    or, maybe you have other plans yet to be implemented. just wanted you to be aware if you were not.

    bug 
    opened by akileez 8
  • jsome.color has no effect for me

    jsome.color has no effect for me

    while

    var jsome = require('jsome');
    jsome.level.show = true;
    jsome.level.color = 'green';
    

    works. I cannot get the following to have any effect:

      jsome.colors = {
          'num'   : 'blue'    // stands for numbers
        , 'str'   : 'blue' // stands for strings
        , 'bool'  : 'blue'     // stands for booleans
        , 'regex' : 'blue'    // stands for regular expressions
        , 'undef' : 'grey'    // stands for undefined
        , 'null'  : 'blue'    // stands for null
        , 'attr'  : 'blue'   // objects attributes -> { attr : value }
        , 'quot'  : 'blue'  // strings quotes -> "..."
        , 'punc'  : 'blue'  // commas seperating arrays and objects values -> [ , , , ]
        , 'brack' : 'blue'  // for both {} and []
      }
      jsome.colors.attr  = ['blue' , 'bold']
    

    Is there a unit test I can run that could help diagnose? node 4.2.1.

    ├─┬ [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ └── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ └── [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ └─┬ [email protected]
    │   ├── [email protected]
    │   ├─┬ [email protected]
    │   │ ├─┬ [email protected]
    │   │ │ ├─┬ [email protected]
    │   │ │ │ └── [email protected]
    │   │ │ └─┬ [email protected]
    │   │ │   └── [email protected]
    │   │ ├─┬ [email protected]
    │   │ │ └── [email protected]
    │   │ └── [email protected]
    │   ├── [email protected]
    │   ├─┬ [email protected]
    │   │ └─┬ [email protected]
    │   │   └── [email protected]
    │   ├── [email protected]
    │   └── [email protected]```
    
    bug 
    opened by edasque 3
  • Display long array one item per line

    Display long array one item per line

    For long arrays:

    Bad:

    ["jetradar_mobile_search", "credit_deeplink_preparation", "credit_deeplink", "airline_deeplink", "mobile_search_native_format", "search", "special_offer_click_builder", "travelpayouts_api_authenticator", "kiwi_assisted_confirm", "pixel_booking", "jetradar_mobile_rt_search_native_format", "jetradar_mobile_search_native_format", "tickets_assisted_deeplink", "stub_chain", "amadeus_chain", "mobile_rt_search", "jetradar_rt_search_native_format", "tickets_assisted_booking", "deeplink", "mobile_rt_search_native_format", "ndc_deeplink", "mobile_search", "special_offer", "ndc_booking", "kiwi_assisted_deeplink", "rt_search_native_format", "non_persisted_deeplink", "travelpayouts_api_request_signer", "kiwi_assisted_booking", "ndc_retrieve", "jetradar_mobile_rt_search"]
    

    Better:

    [
      "jetradar_mobile_search",
      "credit_deeplink_preparation",
      "credit_deeplink",
      "airline_deeplink",
      "mobile_search_native_format",
      "search",
      "special_offer_click_builder",
      "travelpayouts_api_authenticator",
      "kiwi_assisted_confirm",
      "pixel_booking",
      "jetradar_mobile_rt_search_native_format",
      "jetradar_mobile_search_native_format",
      "tickets_assisted_deeplink",
      "stub_chain",
      "amadeus_chain",
      "mobile_rt_search",
      "jetradar_rt_search_native_format",
      "tickets_assisted_booking",
      "deeplink",
      "mobile_rt_search_native_format",
      "ndc_deeplink",
      "mobile_search",
      "special_offer",
      "ndc_booking",
      "kiwi_assisted_deeplink",
      "rt_search_native_format",
      "non_persisted_deeplink",
      "travelpayouts_api_request_signer",
      "kiwi_assisted_booking",
      "ndc_retrieve",
      "jetradar_mobile_rt_search"
    ]
    
    opened by antonmedv 1
  • print object keys in sorted order

    print object keys in sorted order

    Since keys in JSON objects are specified to be unordered, it's legal to print them in any order.

    For pretty-printing purposes, it's nice to have them sorted. This simplifies tasks like looking for a particular key in the output and visually comparing two pretty-printed objects.

    Let me know what you think!

    Thanks, -John

    opened by vvcephei 1
  • Allow lintable JSON output

    Allow lintable JSON output

    As mentioned in #12, when passing the output of jsome(...) into a utility which expects validate JSON (for example,jq) or a JSON linter, errors are thrown as keys are expected to bring wrapped in double quotes as per the JSON spec (members have pairs; pairs have strings on the left size of : and strings have " around them).

    This adds quotes is jsome.params.lintable is set to true, and added a cli option for the cli util.

    opened by drewsonne 1
  • Add getColoredString

    Add getColoredString

    Adds a jsome.getColoredString(obj, cb) method which will just return the colored, formatted, string. This is useful when you want to control when/how it's printed, rather than jsome printing it for you; for example as part of the prettyPrint function of winston logger

    opened by astanciu 1
  • Jsome including uncolored output

    Jsome including uncolored output

    I'm trying to use Jsome in my project, and it works well colorizing the JSON. However, it also includes the uncolored output after the colored output.

    Here's the code I'm using: let colorizedJson = jsome.parse(json);

    where json is just a JSON string. See screenshot to see the behavior. screen shot 2016-10-23 at 7 10 30 pm

    opened by joeattardi 1
  • jsome.colors.attr  = ['blue' , 'bold']; doesn't work

    jsome.colors.attr = ['blue' , 'bold']; doesn't work

          jsome.colors.attr  = ['blue' , 'bold'];
    

    causes this error:

    /Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:92
              return chalk[isArray(color) ? color[0] : color](str);
                                                             ^
    
    TypeError: chalk[(intermediate value)(intermediate value)(intermediate value)] is not a function
        at useColorProvider (/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:92:58)
        at useColorProvider (/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:90:18)
        at useColorProvider (/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:90:18)
        at colorifySpec (/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:76:35)
        at Object.module.exports.color.gen (/Users/edasque/project/jsome_test/node_modules/jsome/lib/generator.js:112:24)
        at Function.module.exports.jsome.parse (/Users/edasque/project/jsome_test/node_modules/jsome/script.js:45:30)
        at jsome (/Users/edasque/project/jsome_test/node_modules/jsome/script.js:31:18)
        at Request._callback (/Users/edasque/project/jsome_test/us_dotd.js:548:4)
        at Request.self.callback (/Users/edasque/project/jsome_test/node_modules/request/request.js:198:22)
    
    bug 
    opened by edasque 1
  • Output is not valid JSON

    Output is not valid JSON

    When passing the output of jsom(...) into a utility which expects validate JSON (for example, jq) or a JSON linter, errors are thrown as keys are expected to bring wrapped in double quotes as per the JSON spec (members have pairs; pairs have strings on the left size of : and strings have " around them).

    Examples:

    $ echo '{"key":"value"}' > test.json && jsome -c false test.json | jq '.'
    > parse error: Invalid numeric literal at line 2, column 6
    

    or if you take the output of

    $ echo '{"key":"value"}' > test.json && jsome -c false test.json

    and put it into https://jsonlint.com/ you get an error:

    Error: Parse error on line 1:
    {	key: "value"}
    --^
    Expecting 'STRING', '}', got 'undefined'
    

    A flag to enable lint friendly JSON whether colours on or not would be beneficial.

    Right now, I check if a user is using TTY (in case they're piping) and I can't just turn colours off (see above), I have to use:

    if (process.stdout.isTTY) {
      process.stdout.write(
        JSON.stringify(jResponse, null, 2)
      )
    } else {
      jsome(jResponse)
    }
    

    whereas I feel a better answer would be

    jsome.params.colored = !process.stdout.isTTY;
    jsome.params.linted = true // Or something like that...
    jsome(jResponse)
    
    opened by drewsonne 0
  • adds yargs for more flexible cli support

    adds yargs for more flexible cli support

    • using yargs to handle cli args
    • now support -l which you can use to show indentation levels
    • prints usage and help

    Could extend this further with additional cli params. I just added the two most obvious ones for now, the one I really wanted was the indentation level, but it at least establishes the pattern.

    opened by kiyanwang 0
  • Did not display undefined properties in objects

    Did not display undefined properties in objects

    const jsome = require('jsome')
    
    const obj = {
      a: 1,
      b: "str",
      c: undefined,
      d: null
    }
    
    console.log( jsome.getColoredString(obj) )
    

    Output is:

    {
      a: 1,
      b: "str",
      d: null
    }
    
    opened by rottmann 0
  • Display array items in lines

    Display array items in lines

    Example: [1, '313233343536373839303132333435367b94679e5264bf84069c68643307ef80c1ebf343565158', 3]

    Output is:

    [1, "313233343536373839303132333435367b94679e5264bf84069c68643307ef80c1ebf343565158", 3]
    

    Output for better readability should be (like object output):

    [
      1,
      "313233343536373839303132333435367b94679e5264bf84069c68643307ef80c1ebf343565158",
      3
    ]
    

    If you had an array of objects it is displayed in lines.

    opened by rottmann 0
  • BREAKING CHANGE: Require Node 8+ (and upgrade yargs)

    BREAKING CHANGE: Require Node 8+ (and upgrade yargs)

    I briefly reviewed the changelogs, and the only relevant thing I found was related to the Node version:

    • https://github.com/yargs/yargs/blob/master/CHANGELOG.md
    • https://github.com/yargs/yargs-parser/blob/master/CHANGELOG.md#breaking-changes

    Node 6 reached end of life earlier this year: https://nodejs.org/en/about/releases/

    Closes #20

    opened by paulmelnikow 0
  • Upgrade to non-vulnerable version of yargs

    Upgrade to non-vulnerable version of yargs

    A vulnerability in mem < 4.0 sindresorhus/mem#14 was fixed in yargs/yargs#1209 and released in 12.0.2 or later.

    I'm seeing an alert in Shields via Danger via jsome.

    It would be great to upgrade!

    opened by paulmelnikow 0
Owner
Khalid REHIOUI
The guy with the username "javascript" at @npm
Khalid REHIOUI
Pathokun, a path generator, updates your content just with your frontend by HTTP GET Request!

Pathokun Pathokun, a path generator, update your content just with your frontend by HTTP GET Request! In this way you can make Full-Stack project with

Pathokun 15 Feb 7, 2022
Find and fix problems in your JavaScript code.

ESLint Website | Configuring | Rules | Contributing | Reporting Bugs | Code of Conduct | Twitter | Mailing List | Chat Room ESLint is a tool for ident

ESLint 22k Jan 8, 2023
Test your internet connection speed and ping using speedtest.net from the CLI

speed-test Test your internet connection speed and ping using speedtest.net from the CLI Install Ensure you have Node.js version 8+ installed. Then ru

Sindre Sorhus 3.8k Jan 7, 2023
:eyeglasses: Node.js module that tells you when your package npm dependencies are out of date.

Node.js module that tells you when your package npm dependencies are out of date. Getting Started Install Node.js. Install david: cd /your/project/dir

Alan Shaw 953 Dec 25, 2022
Get your public IP address - very fast!

public-ip Get your public IP address - very fast! In Node.js, it queries the DNS records of OpenDNS, Google DNS, and HTTPS services to determine your

Sindre Sorhus 962 Dec 25, 2022
Translations with speech synthesis in your terminal as a node package

Normit Normit is an easy way to translate stuff in your terminal. You can check out its Ruby gem version termit. Installation npm install normit -g Us

Paweł Urbanek 234 Jan 1, 2023
Terminal recorder: Record your termial session into HTML

terminal-recorder Terminal recorder allows you to record your bash session, and export it to html so then you can share it with your friends. GitHub P

Cristian Cortez 104 Mar 3, 2022
📜 Create mutable log lines into the terminal, and give life to your logs!

Because Logging can be pretty and fun Installation $ npm install draftlog What it does It allows you to re-write a line of your log after being writt

Ivan Seidel 1.2k Dec 31, 2022
Simple config handling for your app or module

conf Simple config handling for your app or module All you have to care about is what to persist. This module will handle all the dull details like wh

Sindre Sorhus 1k Jan 7, 2023
An extension geared towards Spotify users with larger libraries; view all your playlists that contain a specific song with the click of a button. Designed for Spicetify (https://github.com/khanhas/spicetify-cli)

ViewPlaylistsWithSong An extension developed for Spicetify that allows you to view all the playlists in your library that contain a certain song. Idea

null 21 Dec 13, 2022
HMSC (How Much Stuffs CLI) analyst for your files and folders

HMSC ?? About HMSC (How Much Stuffs CLI) analyst for your files and folders ?? Screenshot ?? Requirements Node.js NPM ?? Installation $ npm i -g hmsc

Abdullah Veliyev 26 Jan 10, 2022
Add a hungry turtle to your terminal and feed it every time you mistype 'npm' as 'nom'

Nom Does this ever happen to you? You happily code away on a project, navigating the command line like a pro, testing, error logging, installing packa

Meike Hankewicz 5 Apr 26, 2022
Google Chrome extension which randomly generates a customisable 3D bamboo forest in your new tab

Bamboo-New-Tab bamboo-new-tab-demo.mp4 bamboo-new-tab-options-demo.mp4 Try it out Hosted version: https://conwayjw97.github.io/Bamboo-New-Tab/ To run

James 15 Nov 16, 2021
A C++ based command-line (CLI) program that lets you manage your tasks

COMMAND LINE INTERFACE TODO APP a command-line (CLI) program that lets you manage your tasks. The specification for this project is written down as te

Rahul Prabhakar 1 Dec 25, 2021
1History is a command line tool to backup your histories of different browsers into one place

1History All your history in one place. 1History is a command line tool to backup your histories of different browsers into one place. Features Suppor

null 340 Dec 31, 2022
DataENV is a cli tool that allows you to save data temporarily using your terminal.

DataEnv CLI Instllation npm install -g dataenv Usage Table of Contents LocalStorage npx dataenv save Parameters npx dataenv show Parameters npx dataen

PGamerX 2 Feb 5, 2022
Fresko - A configurable cli that keeps your project deps fresh

?? Fresko (fresh in Basque) A configurable cli that keeps your project deps fresh Why? Have you ever pulled someone else's code into your local enviro

Quentin Hello 9 Nov 21, 2022
LinkFree CLI is a command line tool that helps you to create your LinkFree profile through CLI.

LinkFree CLI LinkFree CLI is a command line tool that helps you to create your LinkFree profile through CLI. Demo Using the CLI (Commands) Note First

Pradumna Saraf 32 Dec 26, 2022
:sparkles: Modular, scoped CSS with ES6

CSJS allows you to write modular, scoped CSS with valid JavaScript. Features Extremely simple and lightweight Zero dependencies, ~2KB minified and gzi

Ryan Tsao 577 Nov 18, 2022
:sparkles: the homepage of @yourfirstpr

Configuring and running locally If you're interested in running Your First PR locally, please note that this project uses Jekyll. Jekyll is a blog-awa

Your First PR 536 Dec 8, 2022