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

json-concat

v0.0.1

Published

concatenate json files and objects

Downloads

12,285

Readme

json-concat

A Node.js module for concatenating JSON files and objects. Use it in Node.js as a plain, old module, in Connect and Express as a middleware and in your terminal as an executable.

Installation

$ npm install json-concat --save

To install json-concat onto your command line, you may require passing the -g flag. You may also require some sudo powers to make it work.

$ sudo npm install -g json-concat

Usage

As a plain module in your apps


var jsonConcat = require("json-concat");

jsonConcat({
    src: ["appVars.json", "userVars.json"],
    dest: "./config.json"
}, function (json) {
    console.log(json);
});

As a middleware in Connect/Express apps


var express    = require("express"),
    app        = express(),
    jsonConcat = require("json-concat");

app.use(jsonConcat({
    src: ["appVars.json", "userVars.json"],
    dest: __dirname + "/config.json",
    middleware: true
}));

As an executable in the command line

# As simple as this. Output file should be last
$ json-concat file1.json file2.json ouput.json

# for usage tip, invoke with no args
$ json-concat

Notes

  • The options object passed may have the following keys:
    • src:
      • (String) path pointing to a directory
      • (Array) array of paths pointing to files and/or directories
      • defaults to . (current working directory)
      • Note: if this is a path points to a single file, nothing will be done.
    • dest:
      • (String) path pointing to a file in which the JSON output will be written to
      • (Null) assign null to have no file written to
      • defaults to ./concat.json
    • middleware:
      • (Boolean) whether it is being used as a middleware or not
      • defaults to false
  • The callback receives two arguments:
    • err:
      • An error object if an error does occur
    • json:
      • On Sucess, the concatenated json is passed
      • On error, the json will be an empty string ""
  • In Connect/Express apps, the concatenation is done on server requests
  • It is asynchronous, the Node.js way
  • It is forgiving, keeps going even when an error occurs. For example, a non-existent file or syntax errors in json files
  • It is recursive, following the folders specified. Files with the extension .json are considered. Symbolic links are ignored

Use Cases

In most cases, while building an Express app, you will end up using jade as your view engine. Jade allows you to pass a javascript object, which may be JSON, for external variables. Instead of writing all your variables in one file, you may distribute the variables across directories and concatenate them later into one file. Eventually passing it to the jade engine.

Tests and Performance

Build Status Coverage Status

To see the tests run on each commit, go to the project's Travis page. If interested in the algorithms used, please read the notes at the beginning of src/json-concat.coffee.

TODO

  • [x] Include tests (v0.0.0)
  • [ ] Allow Synchronous Execution: be called as a function with splats

// Just an example
var json = jsonConcat("appVars.json", "userVars.json", {"name": "@mugo_gocho"});
console.log(json);
  • [ ] Get the JSON output in a pretty format i.e. with indentations

License

The MIT License (MIT)

Copyright © 2014-2016 GochoMugo [email protected]