1.0.0 • Published 8 years ago

json-flat v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

json-flat

Flatters any JSON properties returning an array of concatenated properties.

npm version Build Status Dependencies status Donate please

Usage

This module might be used from CLI or requiring it.

From CLI

This module might be used from CLI. It parses a given JSON file and returns a list of properties concatenated. Expects these parameters:

  • --path: Path to a JSON file.
  • --separator (Optional): Separator to be used to concatenate properties
$> node json-flat --path ./test.json
foo.bar
foo.bar.string

$> node json-flat --path ./test.json --separator _
foo_bar
foo_bar_string

From require

This module might be imported in other module using require. It parses a given JSON Object and returns an array with all properties concatenated, for example:

var jsonFlat = require('./json-flat'),
  _json = JSON.stringify({
    foo: {
      number: 1,
      bar: {
        string: 'Hello World'
      }
    }
  });

// With default separator
jsonFlat.flat(_json).forEach(function(property) {
  console.log(property);
});
// Prints:
//   foo.number
//   foo.bar.string

// With a given separator
jsonFlat.flat(_json, '_').forEach(function(property) {
  console.log(property);
});
// Prints:
//   foo_number
//   foo_bar_string