def readMetadata(data, key):
    """Safely reads the value of data.metadata[key]."""
    if 'metadata' not in data:
        return None
    m = data['metadata']
    if key not in m:
        return None
    return m[key]