Find a line (JSON-formatted) in the given file where
    all keys in `pattern` are present as keys in the line's
    JSON, and where their values equal the corresponding
    values in `pattern`. Additional keys in the line are
    ignored. If no matching line is found, or if the
    file does not exist, return None.

def find_lines(filename, **pattern):
    """Find a line (JSON-formatted) in the given file where
    all keys in `pattern` are present as keys in the line's
    JSON, and where their values equal the corresponding
    values in `pattern`. Additional keys in the line are
    ignored. If no matching line is found, or if the
    file does not exist, return None.
    """
    if exists(filename):
        with file(filename, 'r') as fp:
            for line in fp:
                try:
                    data = json.loads(line)
                except:
                    continue
                matches = True
                for key, value in pattern.iteritems():
                    matches = matches and key in data and data[key] == value
                if matches:
                    yield data