I am receiving a JSON file from an APIcall (see below). Now, I would like to access the different keys of the JSON file to present the various values separately. However, I get an 'undefined' message in the console. Any ideas?
This is the code to call the API and process JSON file:
const input = req.body.var_1;
console.log('Request Query:' + JSON.stringify({ "user_input": input}));
const articles = [];
const sent = 'test';
const api_url = '...';
const options = {
method: 'POST',
body: JSON.stringify({"user_input": input}),
headers: {'Content-Type': 'application/json'}
}
const response = await fetch(api_url, options);
const results = await Promise.all([response.json()]);
console.log(results);
data = JSON.parse(JSON.stringify(results))
console.log(data);
console.log(data.Topic);
This is the console output I get:
Request Query:{"user_input":"xgboost"}
[
{
Topic: {
'0': 'random forest , Machine Learning and Wine Quality: Finding a good wine using multiple classifications',
'1': 'decision tree learning , Gradient Boost for Classification',
'2': 'feature selection , Understanding Multilabel Text Classification and the related process',
'3': 'decision tree learning , Gradient Boost for Regression',
'4': '<strong class="markup--strong markup--h3-strong">Understanding AdaBoost</strong> , Anyone starting to learn Boosting technique should start first with AdaBoost or…'
},
'URL/PDF': {
'0': 'https://dev.to//leading-edje/machine-learning-and-wine-quality-finding-a-good-wine-using-multiple-classifications-4kho',
'1': 'https://dev.to//xsabzal/gradient-boost-for-classification-2f15',
'2': 'https://dev.to//botreetechnologies/understanding-multilabel-text-classification-and-the-related-process-n66',
'3': 'https://dev.to//xsabzal/gradient-boost-for-regression-1e42',
'4': 'https://towardsdatascience.com/understanding-adaboost-2f94f22d5bfe'
},
Doc_Type: {
'0': 'article',
'1': 'article',
'2': 'article',
'3': 'article',
'4': 'article'
}
}
]
[
{
Topic: {
'0': 'random forest , Machine Learning and Wine Quality: Finding a good wine using multiple classifications',
'1': 'decision tree learning , Gradient Boost for Classification',
'2': 'feature selection , Understanding Multilabel Text Classification and the related process',
'3': 'decision tree learning , Gradient Boost for Regression',
'4': '<strong class="markup--strong markup--h3-strong">Understanding AdaBoost</strong> , Anyone starting to learn Boosting technique should start first with AdaBoost or…'
},
'URL/PDF': {
'0': 'https://dev.to//leading-edje/machine-learning-and-wine-quality-finding-a-good-wine-using-multiple-classifications-4kho',
'1': 'https://dev.to//xsabzal/gradient-boost-for-classification-2f15',
'2': 'https://dev.to//botreetechnologies/understanding-multilabel-text-classification-and-the-related-process-n66',
'3': 'https://dev.to//xsabzal/gradient-boost-for-regression-1e42',
'4': 'https://towardsdatascience.com/understanding-adaboost-2f94f22d5bfe'
},
Doc_Type: {
'0': 'article',
'1': 'article',
'2': 'article',
'3': 'article',
'4': 'article'
}
}
]
undefined
Happy for any help, thx