rhalff / dot-object

Transform json objects using dot notation
MIT License
471 stars 46 forks source link

dot.object fails converting numeric nested json object #48

Open jelhub opened 4 years ago

jelhub commented 4 years ago

Example:

const dot = require('dot-object')

const config = {
  level1: {
    key1: 'val1',
    2222: {
      key2: 'val2'
    }
  },
  3333: {
    key3: 'val3'
  }
}

console.log('original:')
console.log(config)
console.log()

const dotConfig = dot.dot(config)

console.log('should be the same as original:')
console.log(dot.object(dotConfig))

Output shows:

original:
{
  '3333': { key3: 'val3' },
  level1: { '2222': { key2: 'val2' }, key1: 'val1' }
}

should be the same as original:
{
  '3333': { key3: 'val3' },
  level1: [ <2222 empty items>, { key2: 'val2' }, key1: 'val1' ]
}
hey0wing commented 3 years ago

Found the solution: https://stackoverflow.com/a/7794127