I have spent lot of time on this and finally decided to post it here. Problem : I have a csv file I want to upload it on firestore.
- I convert csv to json using json lib in python3
- Upload that json into firestore
from urllib.request import urlopen #No issue
import csv #No issue
import json #No issue
import codecs #No issue
db = firestore.Client() #No issue
def firestore_upload(event, context): #No issue
url = event['mediaLink'] #No issue
print(url) #No issue
csvFile = urlopen(url) #No issue
csvReader = csv.DictReader(codecs.iterdecode(csvFile, 'utf-8')) #No issue
for line in csvReader: #No issue
jsonline = json.dumps(line) #No issue
print(jsonline) #No issue
db_collection_document = db.collection(u'mlacademyRSA').document(None) #No issue
print('inserting record') #No issue
db_collection_document.set(jsonline) #Fails
db_collection_document.set({"ProductID": "00000001"}) # works fine when i try to put raw json data instead of jsonline
I am not able to add jsonline variable into a collection in firestore. But I am able to put raw json data /object into the same collection.
In short line in my code i.e db_collection_document.set({"ProductID": "00000001"}) works fine but not db_collection_document.set(jsonline).
I have checked the validity of json data in jsonline by print jsonline and pasting that output into various json validators they all say its in valid json format. Pls help.
Thanks xytiz