I am writing a parser to grab data from GitHub api, and I would like to output the file into the following .js format:
//Ideal output
var LIST_DATA = [
{
"name": "Python",
"type": "category"
}]
Though I am having trouble writing into output.js
file with the variable var LIST_DATA
, no matter what I do with the string, the end result shows as "var LIST_DATA"
For example:
//Current Output
"var LIST_DATA = "[
{
"name": "Python",
"type": "category"
}]
My Python script:
var = "var LIST_DATA = "
with open('list_data.js', 'w') as outfile:
outfile.write(json.dumps(var, sort_keys = True))
I also tried using strip
method according to this StackOverflow answer and got the same result
var = "var LIST_DATA = "
with open('list_data.js', 'w') as outfile:
outfile.write(json.dumps(var.strip('"'), sort_keys = True))
I am assuming, whenever I am dumping the text into the js file, the string gets passed in along with the double quote... Is there a way around this?
Thanks.