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

easyjson

v0.1.2

Published

An easy way to manipulate JSON file with add/delete/modify/get json data, support nested data.

Downloads

8,291

Readme

easyjson

Tiny node.js module to manipulate JSON file with add/delete/modify/get json data easily. Also support nested datas.

Installation

$ npm install easyjson

Or

$ component install Tinple/easyjson

EasyJSON

With EasyJSON you can simply invoke the exported function to manipulate JSON file. At first, passing a path to path function to choose a JSON file. And EasyJSON support the chain call.

Example app.js:

var easyjson = require('easyjson');

// it should output your JSON file
easyjson.path('test')
    .express();

You can also add, modify or delete a item with your JSON file. And EasyJSON support chained invoke.

var easyjson = require('easyjson');

easyjson.path('test')
    .add('license', 'MIT')
    .express()
    .add('blog', 'http://tinple.me')  
    .express()
    .del('version')
    .express()
    .modify('project', 'EasyJSON')
    .express();

easyjson can get the value of your item with JSON file. Just call get(key) to get it.

var easyjson = require('easyjson'),
  author = easyjson.path('test').get('author'),
  email = easyjson.path('test').get('email');

Most Useful(support nested data)

Actually, EasyJSON support nested data, that means you can manipulate your JSON file most effectivly.

var easyjson = require('easyjson').path('test');

/**
 * "author": {
 *      "name": "Tinple"
 * }
 * ==>
 * "author": {
 *      "name": "Tinple",
 *    "friend": {
 *      "name": "Kristine"
 *    }
 *  }
 */
easyjson.add('author[friend][name]', 'Kristine');

/**
 * push 'path.json' to existed array files
 * "files": ["index.js"]
 * ==>
 * "files": ["index.js", "path.json"]
 */
easyjson.add('files', 'path.json');

// it will delete whole friend object, the same as array
easyjson.del('author[friend]');

// modify the array, only index support
easyjson.modify('files[1]', 'path2.json');

// modify the obj key
easyjson.modify('author[friend][name]', 'Panda');

/** More complex
 * "author": {
 *      "name": "Tinple"
 * }
 * ==>
 * "author": {
 *      "name": "Tinple",
 *    "friend": [{
 *      "name": "Kristine"
 *    }]
 *  }
 */
easyjson.add('author[friend][0][name]', 'Kristine');

Warning

EasyJSON will do nothing when you pass a nonexistent key to modify() and del(). As for add(key, value), EasyJSON will judge whether the key exists firstly. If not, it will added normally.

If it has already existed, there are two situations that the key should be treated.

  1. The key is an array, then the value will be pushed.
  2. The key is other type, like Object or String, then EasyJSON do nothing.

License

MIT