Skip to content

Flattens nested JSON-like JS objects into a flat key-value object

Notifications You must be signed in to change notification settings

segmentio/trample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Segment Trample

npm install @segment/trample

Getting Started

var trample = require('@segment/trample');

trample({ foobar: { bar: ['Hello', 'World'] }}, { flattenArray: true });
// {
//   "foobar.bar.0": "Hello",
//   "foobar.bar.1": "World"
// }

trample({ foobar: { bar: ['Hello', 'World'] }}, { delimiter: '_' });
// {
//   "foobar_bar": ["Hello", "World"]
// }


trample({ foobar: [{ bar: ['Hello', 'World'] }]}, { flattenArray: true });
// {
//   "foobar.0.bar.0": "Hello",
//   "foobar.0.bar.1": "World"
// }

trample({ foobar: [{ bar: ['Hello', 'World'] }]});
// {
//   "foobar.0.bar": ["Hello", "World"]
// }

Options

  • flattenArray: true will flatten arrays
  • delimiter: '_' will delimit by underscores

About

Flattens nested JSON-like JS objects into a flat key-value object

Resources

Stars

Watchers

Forks

Packages

No packages published