JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 22972
  • Score
    100M100P100Q131969F
  • License MIT

Easily edit a json file from the CLI or NodeJS

Package Exports

  • dot-json

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dot-json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dot-json

Build Status

Easily edit a json file from the CLI or NodeJS.

Install global

npm install -g dot-json

or local

npm install --save dot-json

Use from the CLI

dot-json myfile.json user.name "John Doe"
dot-json myfile.json user.email "john@example.com"

myfile.json now looks like

{
    "user": {
        "name": "John Doe",
        "email": "john@example.com"
    }
}
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:
  -d --delete     Delete the key-path
  -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', 'john@example.com').save(function(){
  console.log('saved');
});

synchronous

myfile.set('user.name', 'John Doe').set('user.email', 'john@example.com').save();

myfile.json now looks like

{
    "user": {
        "name": "John Doe",
        "email": "john@example.com"
    }
}

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": "john@example.com"
    }
}

npmjs.org/package/dot-json