CodingTrain / CodingTrain/Suggestion-Box
Trying to insert specific data into JSON
- Dominant language
- No language data
- Stars
- 570
- Forks
- 85
- PR merge metrics
- No merged PRs in 30d
Description
I have been taking your NodeJS classes and learning JS as well, I was able to mess around with a giphy API that I found and got as far as outputting the res.data into a JSON file..However 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, 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' then of course it outputs the entire API data.
Not sure what is happening, is anyone able to help?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.