1

I tried this python code but it didn't work its keep running without any result:


import json_lines
import csv

data = []

with open('xaa', 'rb') as f:
    for item in json_lines.reader(f):
        data.append(item)

with open('data.csv', 'w', encoding='utf-8') as f:
    writer = csv.writer(f)
    writer.writerow(data[0].keys())
    for row in data:
        writer.writerow(row.values())

This is an example of my json file

{"id":"DRNpiztMCKx2wgVj5yAbsQ_0000","full_name":"maitê chaves","first_name":"maitê","middle_initial":null,"middle_name":null,"last_name":"chaves","gender":null,"birth_year":null,"birth_date":null,"linkedin_url":"linkedin.com/in/maitê-chaves-47b8033a","linkedin_username":"maitê-chaves-47b8033a","linkedin_id":"139351775","facebook_url":null,"facebook_username":null,"facebook_id":null,"twitter_url":null,"twitter_username":null,"github_url":null,"github_username":null,"work_email":null,"mobile_phone":null,"industry":"government relations","job_title":"customer service clerk","job_title_role":"customer_service","job_title_sub_role":null,"job_title_levels":[],"job_company_id":"condominio-do-shopping-leblon","job_company_name":"condominio do shopping leblon","job_company_website":null,"job_company_size":"1-10","job_company_founded":null,"job_company_industry":"utilities","job_company_linkedin_url":"linkedin.com/company/condominio-do-shopping-leblon","job_company_linkedin_id":"24527628","job_company_facebook_url":null,"job_company_twitter_url":null,"job_company_location_name":"rio de janeiro, rio de janeiro, brazil","job_company_location_locality":"rio de janeiro","job_company_location_metro":null,"job_company_location_region":"rio de janeiro","job_company_location_geo":null,"job_company_location_street_address":null,"job_company_location_address_line_2":null,"job_company_location_postal_code":null,"job_company_location_country":"brazil","job_company_location_continent":"south america","job_last_updated":"2020-10-01","job_start_date":"2018-09","job_summary":null,"location_name":"chelmsford, essex, united kingdom","location_locality":"chelmsford","location_metro":null,"location_region":"essex","location_country":"united kingdom","location_continent":"europe","location_street_address":null,"location_address_line_2":null,"location_postal_code":null,"location_geo":"51.73,.48","location_last_updated":"2020-08-01","linkedin_connections":276,"inferred_salary":"<20,000","inferred_years_experience":15,"summary":"Develop activities with maximum commitment, professionalism and punctuality, as well as overcome the new challenges collaborating with the company to achieve its goals and its growth always emphasizing quality and respecting deadlines.\n\nAbilities:\nEnglish (advanced level);\nFrench (intermediary);\nSpanish (basic);\nExcellence in service;\nExecutive secretary;\nEnglish/Portuguese Translation;\nManaging Diversity;\nCommunication Essentials : effective public speaking;","phone_numbers":[],"emails":[],"interests":[],"skills":["microsoft office","microsoft excel","microsoft word","pacote office","powerpoint","ariba","foco no cliente","trabalho em equipe","microsoft outlook","mxm","lotus notes","wise it","citrix"],"location_names":["itatiba, sao paulo, brazil","niteroi, rio de janeiro, brazil","rio de janeiro, rio de janeiro, brazil","kitchener, ontario, canada","redhill, surrey, united kingdom","chelmsford, essex, united kingdom","sao paulo, sao paulo, brazil"],"regions":["rio de janeiro, brazil","surrey, united kingdom","essex, united kingdom","sao paulo, brazil","ontario, canada"],"countries":["united kingdom","canada","bangladesh","portugal","brazil"],"street_addresses":[],"experience":[{"company":{"name":"technip","size":"10001+","id":"technip","founded":"1958","industry":"oil & energy","location":null,"linkedin_url":"linkedin.com/company/technip","linkedin_id":"5124","facebook_url":"facebook.com/technipgroup","twitter_url":"twitter.com/technipgroup","website":"technip.com"},"start_date":"2005-02","end_date":"2005-12","title":{"name":"bilingual recepcionist","role":null,"sub_role":null,"levels":[]},"location_names":[],"is_primary":false,"summary":"* Telephone and customer services\n* Release of badges for visitors and temporary badges for employees\n* Register of visitors and suppliers\n* Sending and receiving pouches and correspondences."},{"company":{"name":"condominio do shopping leblon","size":"1-10","id":"condominio-do-shopping-leblon","founded":null,"industry":"utilities","location":{"name":"rio de janeiro, rio de janeiro, brazil","locality":"rio de janeiro","region":"rio de janeiro","metro":null,"country":"brazil","continent":"south america","street_address":null,"address_line_2":null,"postal_code":null,"geo":null},"linkedin_url":"linkedin.com/company/condominio-do-shopping-leblon","linkedin_id":"24527628","facebook_url":null,"twitter_url":null,"website":null},"location_names":[],"end_date":null,"start_date":"2018-09","title":{"name":"customer service clerk","role":"customer_service","sub_role":null,"levels":[]},"is_primary":true,"summary":null},{"company":{"name":"technip","size":"10001+","id":"technip","founded":"1958","industry":"oil & energy","location":null,"linkedin_url":"linkedin.com/company/technip","linkedin_id":"5124","facebook_url":"facebook.com/technipgroup","twitter_url":"twitter.com/technipgroup","website":"technip.com"},"location_names":["rio de janeiro, rio de janeiro, brazil"],"end_date":"2011-12","start_date":"2008-01","title":{"name":"documentation assistant","role":null,"sub_role":null,"levels":[]},"is_primary":false,"summary":"* ARTEC (Data Book)\n* P-51 & P-56 Projects:\n* Assembly of data books (group of documents referent to the equipments that compose a platform, such as: drawings, data sheets, memory calculation, technical specifications) in hardcopies as electronic copies in accordance with PNBV rules.\n* Send to client’s approval – PNBV.\n* ARTEC (Document Control)\n* P-58 & P-62 Projects:\n* Register of electronic files issued for the subcontracted companies, as well as all other documents referent to them up to the workflow end.\n* Translation of supplier's Operations and Maintenance Manuals from English into Portuguese, and vice-versa;\n* Contact with national and international suppliers by e-mail and telephone."},{"company":{"name":"rp1 representações e consultoria","size":null,"id":null,"founded":null,"industry":null,"location":null,"linkedin_url":null,"linkedin_id":null,"facebook_url":null,"twitter_url":null,"website":null},"location_names":["rio de janeiro, rio de janeiro, brazil"],"end_date":"2008-01","start_date":"2005-12","title":{"name":"board secretary","role":null,"sub_role":null,"levels":[]},"is_primary":false,"summary":"* Telephone and customer services\n* Composing, interpretation, review, analysis, translation and summary of texts and documents in English and Portuguese\n* Send and receipt of mailing\n* Organization of director’s documentation, appointments and personal file\n* Organization of trips\n* Organization of meetings."},{"company":{"name":"rp1 representações e consultoria","size":null,"id":null,"founded":null,"industry":null,"location":null,"linkedin_url":null,"linkedin_id":null,"facebook_url":null,"twitter_url":null,"website":null},"location_names":["rio de janeiro, rio de janeiro, brazil"],"end_date":"2007-12","start_date":"2007-06","title":{"name":"commercial assistant","role":null,"sub_role":null,"levels":[]},"is_primary":false,"summary":"* Creation, updating, maintenance of worksheets\n* Selection of information about project that would be interesting for the company\n* Contact with clients aiming the sale of the products manufactured for the companies represented."},{"company":{"name":"u.s. department of state","size":"10001+","id":"u-s--department-of-state","founded":null,"industry":"international affairs","location":{"name":"washington, district of columbia, united states","locality":"washington","region":"district of columbia","metro":"district of columbia","country":"united states","continent":"north america","street_address":"2201 c street northwest","address_line_2":null,"postal_code":"20520","geo":"38.89,-77.03"},"linkedin_url":"linkedin.com/company/u-s--department-of-state","linkedin_id":"3100","facebook_url":"facebook.com/usdos","twitter_url":"twitter.com/statedept","website":null},"location_names":["washington, district of columbia, united states"],"end_date":"2015-06","start_date":"2012-01","title":{"name":"visa clerk","role":null,"sub_role":null,"levels":[]},"is_primary":false,"summary":"* Responsible for visa applicant’s data register into the system (DHS-NIV)\n* Visa printing and pasting\n* Visa quality control assurance\n* Scanning documents into the system (DHS-NIV)\n* Simultaneous translation\n* Participation in the Project created aiming to reduce the time spent by the applicant inside the\n* Consulate (Rio -20)\n* Responsible for ordering, purchasing and receiving office supplies through Ariba Portal\n* Responsible for controlling IT supplies\n* Responsible for requesting office maintenance\n* Participation in Green Committee\n* Participation in Students Fair."}],"education":[{"school":{"name":"universidade candido mendes","type":"post-secondary institution","id":"CN-DJeheJ6OASfpY1rSlig_0","location":{"name":"brazil","locality":null,"region":null,"country":"brazil","continent":"south america"},"linkedin_url":"linkedin.com/school/universidadecandidomendes","facebook_url":null,"twitter_url":null,"linkedin_id":"3181003","website":"ucam.edu.br","domain":"ucam.edu.br"},"degrees":[],"start_date":"2018","end_date":"2019","majors":["teaching","english","education"],"minors":[],"gpa":null,"summary":null},{"school":{"name":"estácio","type":"post-secondary institution","id":"Bf58Cf8ECnESNyRGNZ4V9w_0","location":{"name":"brazil","locality":null,"region":null,"country":"brazil","continent":"south america"},"linkedin_url":"linkedin.com/school/estacio","facebook_url":"facebook.com/br.estacio","twitter_url":null,"linkedin_id":"4053016","website":"estacio.br","domain":"estacio.br"},"end_date":"2008","start_date":"2007","gpa":null,"degrees":[],"majors":["education","linguistics"],"minors":[],"summary":null},{"school":{"name":"estácio","type":"post-secondary institution"

  • 2
    I tested your program, and it seems to run fine, giving an output of `1,2,3,4,5 6,7,8,9,10`. However, the json you posted isn't valid, as I had to add `}}]}` right to the end to make the program even accept it. If you could update your example json data, as well as explaining in more detail what you expect to happen and what actually happens, I would should be able to help you with your problem. – Cmd858 May 07 '23 at 23:11
  • Hi @Cmd858 Yes I know it work on sample test data but it stack when it come to 2go file. – salaheddine Rmaili May 11 '23 at 00:03
  • could this be because you are filling a list with 2GB worth of data? I don't think python would find it very easy to create such a big list, so you should probably write the data directly to the csv file without storing it in a massive list. I can answer with an example of how I would try to do this if you would like. – Cmd858 May 11 '23 at 10:41
  • Hi @Cmd858 I think if there is an example of what you said it will help – salaheddine Rmaili May 13 '23 at 16:11

0 Answers0