deep.json thumbnail

deep.json

A better way to load big json config files in node.js apps

Star Fork Follow @jacoborus

Why

Sometimes config files grow to sizes that are difficult to handle, therefore it is desirable to distribute information in different files and folders.

If you hand out your config in files inside a folder named as your main json config file, deepjson will populate it with this folder data. deepjson will also extend this object with the following files (and its trees) that you have passed as arguments.

Example

.jsons and folders structure:

default.json
{
  "appName": "MyApp",
  "port": 3000
}
production.json
{
  "port": 4444
}
default (folder)
seo.json
{
  "description": "We load configs"
}
seo (folder)
keywords.json
[
  "a",
  "big",
  "array"
]
var deepjson = require( 'deepjson' );

var defaultConfig = deepjson( 'default' );
/* {
    appname: 'MyApp',
    port: 3000,
    SEO: {
        description: 'We load configs',
        keywords: ['a', 'big', 'array']
    }
} */

var productionConfig = deepjson( 'default', 'production' );
/* {
    appname: 'MyApp',
    port: 4444,
    SEO: {
        description: 'We load configs',
        keywords: ['a', 'big', 'array']
    }
} */

Installation

Install with npm

$ npm install deepjson

API

deepjson( jsonFile1, jsonFile2, … )

Load all the json files passed as arguments, then extend them with json files under the folders with same name. Deepjson will return a object result of extend loaded files in order.

Parameters:

Tests

npm install && npm test




© 2015 Jacobo Tabernero

Released under MIT License