def generateD3Object(wordCounts, objectLabel, wordLabel, countLabel):
    """
    Generates a properly formatted JSON object for d3 use.

    Args:
        objectLabel: The label to identify this object.
        wordLabel: A label to identify all "words".
        countLabel: A label to identify all counts.

    Returns:
        The formatted JSON object.
    """
    JSONObject = {}

    JSONObject['name'] = str(objectLabel.encode('utf-8'))

    JSONObject['children'] = []

    for word, count in wordCounts.items():
        JSONObject['children'].append({wordLabel: word.encode('utf-8'), countLabel: count})

    return JSONObject