objectdotnotate

1.0.5 • Public • Published

# ObjectDotNotate

Build Status Coverage Status

ObjectDotNotate turns nested json objects into dotted strings with their corresponding values it takes in an object and returns an object with string notation of all nested objects . This comes in handy when you are filtering a mongo db query using a nested object or a smiple object.

Installation

 npm i objectdotnotate

Usage

 var objectdotnotate = require('objectdotnotate');

Example

 var data = {
      obj: "obj",
      nested_once: { first: "first" },
      nested_twice: {
          twice: { inner_nest: { second: "second" } }
      },
      nested_thrice: {
          thrice: { second_nest: { tripple_nest: { tripple: "thrice" }, three: "three" } }
      }
  }

call the relevant method to convert our object

    var returnedObj = objectdotnotate(data)

returnedObj output

        console.log(returnedObj)

  {
    obj: 'obj',
    'nested_once.first': 'first',
    'nested_twice.twice.inner_nest.second': 'second',
    'nested_thrice.thrice.second_nest.tripple_nest.tripple': 'thrice',
    'nested_thrice.thrice.second_nest.three': 'three'
  }

If an object passed in has an array value, Then the output will be as below

Example

data={
    obj: "obj",
        nested_once: { first: "first" },
        nested_twice: {
            twice: { inner_nest: [1,2,3,4,5] }
        }
}

conversion

returnedObj = objectdotnotate(data)

output

console.log(returnedObj)

{
  obj: 'obj',
  'nested_once.first': 'first',
  'nested_twice.twice.inner_nest': [ 1, 2, 3, 4, 5 ]
}

The returned object can easily be looped over while filtering a query.

Don't pass in an array of objects.

Dependencies (4)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i objectdotnotate

    Weekly Downloads

    1

    Version

    1.0.5

    License

    MIT

    Unpacked Size

    4.62 kB

    Total Files

    4

    Last publish

    Collaborators

    • kenneth051