Skip to content

Instantly share code, notes, and snippets.

@compilerexe
Last active December 11, 2017 08:59
Show Gist options
  • Save compilerexe/e04e412bca33dcda9a7e9e8c89549703 to your computer and use it in GitHub Desktop.
Save compilerexe/e04e412bca33dcda9a7e9e8c89549703 to your computer and use it in GitHub Desktop.
const mockup = {
'info': {
'ssid': 'CMMC-4G-GATEWAY',
'flash_size': 4194304,
'flash_id': '1640a1',
'chip_id': 'eecda8',
'sdk': '2.0.0(656edbf)',
'mac': '18:FE:34:EE:CD:A8',
'id': '15650216',
'client_id': '15650216',
'device_id': '15650216',
'prefix': 'CMMC/BANANA/',
'ip': '192.168.100.202',
'version': 0.99
},
'd': {
'myName': 'NODE-01',
'millis': 46669,
'temperature_c': 30.20,
'humidity_percent_rh': 84.30,
'state': 0,
'heap': 37656,
'rssi': -90,
'counter': 7,
'nodes': {
node1: 'this is node 001',
node2: 'this is node 002',
node3: {
name: 'node003',
sub_nodes: {
n1: 'ok',
nested: {
name: 'hello world'
}
}
}
},
'subscription': 1
},
't': {
test: '123'
}
}
const resolve_nested = (k, d, r) => {
const n = d || mockup
for (let key in n) {
if (n.hasOwnProperty(key)) {
if (typeof(n[key]) === 'object') {
if (k !== undefined) {
if (r !== undefined) {
console.log(`----- +++++ /${r}/${k}/${key}`)
} else {
console.log(`----- /${k}/${key}`)
}
resolve_nested(key, n[key], k)
} else {
console.log(`/${key}`) // this is root object
resolve_nested(key, n[key])
}
} else {
if (r !== undefined) {
console.log(`----- +++++ /${r}/${k}/${key}`) // this is children object
} else {
console.log(`----- /${k}/${key}`) // this is children object
}
}
}
}
}
const _initial = () => {
resolve_nested()
}
_initial()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment