I want to be able to only save specific data from the output of the API...
function getGiph() {
giphy.search({
q: 'pratt',
}, function (err, res) {
var gif = res.data;
for (var i = 0; i < gif.length; i++) {
var embed = gif[i].embed_url;
fs.writeFile('./apidata.json', JSON.stringify(embed, undefined, 1), function (err) {
if (err) throw err;
console.log('saved');
});
}
});
}
This is my code, when I console.log(embed);
it outputs only the embed_urls of the API in the terminal just like I want, but when I write to the JSON it outputs "https://giphy.com/embed/XqOCxN1WpEzja"MsM0""
and that is all...
If I replace 'embed'
with 'gif'
in the fs.writeFile()
, then of course it writes the entire API data to the JSON.
I have tried JSON.stringify(gif, undefined, 1)
,
JSON.stringify(embed, undefined, 1)
.
I honestly searched and searched I hardly ever ask questions because I almost always find a solution but this one has me, I am pretty new to all this as well.