npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dot-json

v1.3.0

Published

Easily edit a json file from the CLI or NodeJS

Downloads

170,728

Readme

dot-json

huntr


Easily edit a json file from the CLI or NodeJS.

Install global

npm install -g dot-json

or local

npm install dot-json

Use from the CLI

dot-json myfile.json user.name "John Doe"
dot-json myfile.json user.email "[email protected]"
dot-json myfile.json foo..bar baz
dot-json myfile.json address '{"city":"Atlantis"}' --json-value

myfile.json now looks like

{
    "user": {
        "name": "John Doe",
        "email": "[email protected]"
    },
    "foo.bar": "baz",
    "address": {
        "city": "Atlantis"
    }
}
dot-json myfile.json user.name
John Doe
Usage:
  dot-json <file> <key-path>             Get a value from a json file by key-path
  dot-json <file> <key-path> <value>     Assign a value at a key-path
  dot-json <file> <key-path> --delete    Delete a key by key-path

Options:
  --indent=<n>      Indent with <n> of white space characters [default: auto] [--json-value]
  -d --delete       Delete the key-path
  -j --json-value   Parse the input value as a JSON string (to set whole objects or arrays)
  -h --help         Show this message with options
  -v --version      Print the version number

Quick tip for editing package.json

Add to .bash_profile:

alias package="dot-json package.json"

Use it like this:

package name "my-package"

Use it in NodeJS

Initialization

var DotJson = require('dot-json');
var myfile = new DotJson('myfile.json');

Writing

asynchronous

myfile.set('user.name', 'John Doe').set('user.email', '[email protected]').save(function(){
  console.log('saved');
});

synchronous

myfile.set('user.name', 'John Doe').set('user.email', '[email protected]').save();

myfile.json now looks like

{
    "user": {
        "name": "John Doe",
        "email": "[email protected]"
    }
}

Reading

asynchronous

myfile.get('user.name', function(value){
  // value = 'John Doe'
  console.log(value);
});

synchronous

var value = myfile.get('user.name');
// value = 'John Doe'
console.log(value);

Deleting

asynchronous

myfile.delete('user.name').save(function(){
  console.log('saved');
});

synchronous

myfile.delete('user.name').save();

myfile.json now looks like

{
    "user": {
        "email": "[email protected]"
    }
}

npmjs.org/package/dot-json