I have to read a json file, I followed the following code: stackoverflow
Trying the example shown in the comment, but it's not working for me.
I have to read this file that I have locally, but I'm not succeeding.
Can you give me a hand?
Link: Codesandbox
Code:
fetch("/user.json")
.then(res => res.json())
.then(res => res.results)
.then(res => {
console.log(res);
let u = res.map((suggestion, i) => ({
label: suggestion.email,
name: suggestion.name.first,
surname: suggestion.name.last,
address: suggestion.location.street.name,
email: suggestion.email,
picture: suggestion.picture.thumbnail
}));
let options =
inputLength === 0
? []
: u.filter(suggestion => {
const keep =
count < 5 &&
suggestion.label &&
suggestion.label.slice(0, inputLength).toLowerCase() ===
inputValue;
if (keep) count += 1;
return keep;
});
this.setState({ options });
})
.catch(e => console.log("Er:", e));