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

jme

v1.1.1

Published

Fully or partially merge JSON objects from the command line

Downloads

918

Readme

JME CLI

CircleCI Codecov NPM

Fully or partially merge JSON files via the command line.

Installation

npm install jme

Usage

jme file-1.json file-2.json file-3.json > merged.json

file-3.json will be merged with file-2.json and the result will be merged with file-1.json The first file is the target file however, files are never modified, rather the merge result is sent to standard out.

You can pass in any number of files to be merged.

Partial merging

In addition to fully merging json files, you can merge only some of the properties / paths on the JSON object.

Given these files:

// test-1.json
{
  "prop1": {
    "id": 1,
    "tags": [1, 2, 3],
    "level1": {
      "prop1": "t1",
      "customProp1": "t1",
      "level2": { // override this path with the same path from the other files.
        "prop1": "t1",
        "customProp1": "t1"
      }
    }
  }
}


// test-2.json
{
  "prop1": {
    "id": 2,
    "tags": [4, 5, 6],
    "level1": {
      "prop1": "t2",
      "customProp2": "t2",
      "level2": { //merge only this path
        "prop1": "t2",
        "customProp2": "t2"
      }
    }
  }
}

You can choose to merge only a part of the file (in this case prop1.level1.level2)

jme test-1.json test-2.json -p 'prop1.level1.level2'

result:

{
  "prop1": {
    "id": 1,
    "tags": [1, 2, 3],
    "level1": {
      "prop1": "t1",
      "customProp1": "t1",
      "level2": {       //only this path 'prop1.level1.level2' is merged
        "prop1": "t2" // comes from test-2.json
        "customProp2": "t2",// comes from test-2.json
        "customProp1": "t1" // comes from test-1.json
      }
    }
  }
}

You can partially merge multiple paths, just make sure to separate then with comma -p 'prop1.level1.level2,some.other.path,yet.some.other.path'

If the path does not exist in one of the files program will report an error and the merge process will not be executed. However, you can pass an additional flag -u or --allow-undefined to allow undefined paths in the files. In that case, if the path does not exist in the file, that file will be skipped for that particular path.

Full path override

You can also override the path on the last file target ( -o or --override)

In the next example chosen path will be merged from test-3.json into test-2.json and then that same path will be overridden in test-1.json (no merging with the test-1.json)

Example:

jme test-1.json test-2.json test-3.json --path 'prop1.level1.level2' --override