My csv is below. I need to convert into json using AWS lambda using python
value,Name,flag
ABC,[email protected]|[email protected],Y
ABC,[email protected],Y
CDE,[email protected],N
CDE,[email protected],N
Code is below
import boto3
import csv
s3_read = boto3.client('s3')
obj = s3_read.get_object(Bucket=bucket, Key=key)
CSVcontent = obj['Body'].read().decode('utf-8').split('\n')
CSVfile = csv.reader(CSVcontent)
print('CSVfile', list(CSVfile))
My current out is
[['value', 'Name', 'flag'], ['ABC', '[email protected]|[email protected]', 'Y'], ['ABC', '[email protected]', 'Y'], ['CDE', '[email protected]', 'N'], ['CDE', '[email protected]', 'N']]
- I need to merge all the same keys and same flag
- I need to change all the
|to different string
Expected out is below
[{'value': 'ABC', 'name': ['[email protected]','[email protected]','[email protected]'], 'flag': 'Y'},
{'value': 'CDE', 'name': ['[email protected]','[email protected]'], 'flag': 'N'}]