Reputation: 1019
I use this code to read lines from json file and insert them in DynamoDB via Lambda:
obj= s3.get_object(Bucket=b, Key=jsonFile)
recList=obj['Body'].read().split('\n')
for row in recList:
table.put_item(Item=json.loads(row))
After all lines are inserted, I get this error:
no json object could be decoded
I checked and found that my json file ends with an empty row. How can I correct my code by checking for each row if it is empty or not please? Or even better, ignore the last row as I am sure it is only the last line that is empty.
Thank you.
Upvotes: 0
Views: 535
Reputation: 827
How about
obj= s3.get_object(Bucket=b, Key=jsonFile)
recList=obj['Body'].read().split('\n')
for row in recList:
if row.strip():
table.put_item(Item=json.loads(row))
Upvotes: 2