javascript - Writing JSON data to a file incorrectly -


i'm reading information api returns text in json format. want take text , write file. when writes \ in front of looks .

[{ \"elementa":\"valuea" ... }] 

here's i've tried

var info = [] request('someapi', function(err, res, body) {   if (err) {     return console.log('error:', err);   }   if (res.statuscode != 200) {     return console.log('invalid:' + res.statuscode);   }   info = json.stringify(body);   fs.writefile('public/file', info); }); 

also file i'm trying write .js if makes difference. desired output :

 [{ "elementa": "value ...}] 

as data trying write formed json, don't have json.stringify , can write is, this

fs.writefile('public/file', body, callbackfunction); 

note: fs.writefile async function. need pass callback function well, invoked when actual writing completed.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -