🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

json-merge

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-merge

given two streams of newline delimited JSON data perform a merge/extend on each object in the stream

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
2
Created
Source

json-merge

given multiple streams of newline delimited JSON data perform a merge/extend on each object in the stream

NPM dat

usage

npm install json-merge -g
Usage: json-merge <source1> [options] <source2> [options] [<source3>...]

Options
--parse=<s>	 Parse the precedent source with <s>

sources can be one of 3 things:

  • paths to newline-delimited json data files
  • HTTP uris that return newline-delimited json data
  • JSONStream selector syntax to be used to parse stdin into a stream of JS objects

examples

newline delimited json files

e.g. given a file a.json:

{"foo": "bar"}

and a file b.json:

{"taco": "pizza"}

then running:

json-merge a.json b.json

would output:

{"foo": "bar", "taco": "pizza"}

JSONStream parsing

you can also specify JSONStream query syntax and json-merge will parse stdin

e.g. if foobar.json is:

{
  "data": [
    {
      "a": {
        "all": "lowercase"
      },
      "b": {
        "ALL": "CAPS"
      }
    }
  ]
}

then running:

cat foobar.json | json-merge "data.*.a" "data.*.b"

would output:

{"all":"lowercase","ALL":"CAPS"}

Parsing different sources

A given a file food1.json:

{
  "salty": 
    {
      "tacos": "muybien",
      "pretzel": "jawohl"
    }
}

and a file food2.json:

{
  "sweet":
    {
      "waffle": "delicious",
      "pancake": "yummy"
    }
}

then running:

json-merge food1.json --parse="salty" food2.json --parse="sweet"

would output:

{"tacos":"muybien","pretzel":"jawohl","waffle":"delicious","pancake":"yummy"}

Keywords

stream

FAQs

Package last updated on 18 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts