import json, sys
from collections import defaultdict
# Input is an explicitly normalized source export, not a vendor API envelope.
groups = defaultdict(list)
for row in json.load(open(sys.argv[1], encoding='utf-8')):
    key = (row['assetId'], row['cve'], row['package'], row['version'])
    groups[key].append({'source': row['source'], 'sourceId': row['sourceId'],
                        'observedAt': row['observedAt']})
for key, sources in sorted(groups.items()):
    print(json.dumps({'assetId': key[0], 'cve': key[1], 'package': key[2],
        'version': key[3], 'sources': sources, 'agencyEvaluationRequired': True}))
