Q:

Generic method for adding list of objects to a dictionary with node.js

I'm new to node.js (like, this is day two). I've written a script that reads a JSON file containing a list of users, parses them and then adds each user to a dictionary keyed by usedrname. Since I'm so new, I was wondering if there was a more elegant or off-the-shelf solution than the one I came up with.
Suppose I'm reading a file called /users.json that contains:
{
    "user1": {
        "first": "Tom",
        "last": "Hanks",
        "job-description": "Movie star"
    },
    "user2": {
        "first": "Dick",
        "last": "Trickle",
        "job-description": "Bar mitzvah entertainer"
    },
    "user3": {
        "first": "Harry",
        "last": "Houdini",
        "job-description": "Escapologist"
    }
}

And my code to create the user dictionary looks something like this:
const fs = require('fs')

var users = fs.readFile(__dirname + '/users.json', 'utf8', (err, users) => {
    users = JSON.parse(users)
    var userDictionary = toDictionary(users)
    console.log('user dictionary', JSON.stringify(userDictionary, null, 4))
}

function toDictionary(objects)
    var dict = {}
    Object.keys(objects).forEach((key, object) => {
        if (objects.hasOwnProperty(key)) {
            dict[key] = objects[key] // copy whole element to dictionary
        }
    })
    return dict
}

This produces the following on the console:
user dictionary {
    "user1": {
        "first": "Tom",
        "last": "Hanks",
        "job-description": "Movie star"
    },
    "user2": {
        "first": "Dick",
        "last": "Trickle",
        "job-description": "Bar mitzvah entertainer"
    },
    "user3": {
        "first": "Harry",
        "last": "Houdini",
        "job-description": "Escapologist"
    }
}

Like I said, my code produces the results I want but is this the best way to achieve them? Thanks in advance!

A:

you are doing duplicate work here, the users object is already a dictionary with username as key!

