in Technology by
How can we write JSON data to a file?

1 Answer

0 votes
by
You forgot the actual JSON part - data is a dictionary and not yet JSON-encoded. Write it like this for maximum compatibility (Python 2 and 3): import json with open('data.json', 'w') as f: json.dump(data, f) On a modern system (i.e. Python 3 and UTF-8 support), you can write a nicer file with import json with open('data.json', 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=4)

Related questions

0 votes
    Can We use comments inside a JSON file? If so, how?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    Can we use JSON instead of YAML while developing docker-compose file in Docker?...
asked Jun 21, 2021 in Technology by JackTerrance
0 votes
    How can we POST JSON data with cURL?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    Which of the following is correct? A.We can use json data directly in axios B.we can use json data directly ... only we can use axios Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    How can we pretty-print JSON in a shell script?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    Why can't we Python parse this JSON data?...
asked Jan 11, 2021 by JackTerrance
0 votes
    I'm completely new in logging but familiar in SQL queries. I'm now experimenting with Serilog and Seq. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    My code is about bookStore with list of books. I need to extract all data(books) from a JSON file and put them in a ... console.log(e); } } function bookToHTMLRow(book) { return `...
asked May 14, 2022 in Education by JackTerrance
0 votes
    How can we combine a database and the flat file data in Tableau Desktop?...
asked Oct 30, 2020 in Technology by JackTerrance
0 votes
    I have a JSON File with database environment configuration called env-config.json like this: { "LATEST":{ ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I have a json file contains a icons object like this: "icons" : { "logo" : "fa fa-caret-down ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Which utilities can we use to export data from sql server to a text file? (a) DTS export wizard ( ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    So, I wanted to run the local Swagger UI with respect to Local Json. And for that I am following ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    Syntax to create a DataFrame based on the content of a JSON file 1. spark.textfile("examples/src/main/resources/data. ... 4. spark.json("examples/src/main/resources/data.json")...
asked Oct 22, 2020 by JackTerrance
0 votes
    How to pass json format data on ajax call?...
asked Dec 10, 2020 in Technology by JackTerrance
...