json-flat
v1.0.0
Published
Flatters any JSON properties returning an array of concatenated properties
Downloads
63
Readme
json-flat
Flatters any JSON properties returning an array of concatenated properties.
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