Created
August 24, 2017 20:03
-
-
Save jamesxv7/18b0cde3e343af8816df6b3e43efdfa8 to your computer and use it in GitHub Desktop.
Nested reading of a json structure using Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
var total = 0 | |
fs.readFile('lists.json', 'utf8', function (err, data) { | |
if (err) throw err; | |
obj = JSON.parse(data); | |
for (var user in obj) { | |
console.log('Lists from', user) | |
for (var list in obj[user]) { | |
lists = obj[user] | |
for (var item in lists[list]) { | |
items = lists[list] | |
if (typeof (items[item]) === 'object') { | |
total += Object.keys(items[item]).length | |
} | |
} | |
} | |
console.log(total) | |
total = 0 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment