I have file.json that contains
{"list" : [
]}
I have this dict
lead = {'title': i.css('article>.sales-info>h1::text').extract_first(),
'address': i.css('article>.primary-info>.contact>h2::text').extract_first(),
'phone': i.css('article>.primary-info>.contact>.phone::text').extract_first(),
'time': i.css('article>.primary-info>.contact>.time-info>div:nth-child(2)::text').extract_first(),
'website': i.css('.business-card-footer>.website-link::attr(href)').extract_first(),
'email': i.css('.business-card-footer>.email-business::attr(href)').extract_first(),
'portfolio_item': ''}
I need to append this dict to the json list.
I've tried basic writing to file
with open('leads.json', 'a') as f:
f.write(json.dumps(item))
f.close()
Have no idea how should i append it to the json list
<data>['list]attribute of the json and append that then rewrite the json. Do you have any other data at the root of your json? or is it just the list of leads?leaddict is passed on trough the system, basically i would need to load the list every time a newleaditem is generated. It's a back and forward process that would waste resources and would be very unprofessional.