Answers for "fetch data from json in javascript"

4

how get a json object from an api in javascript

let url = 'https://example.com';

fetch(url)
.then(res => res.json())
.then((out) => {
  console.log('Checkout this JSON! ', out);
})
.catch(err => { throw err });
Posted by: Guest on March-17-2020
79

javascript parse json

var jsonPerson = '{"first_name":"billy", "age":23}';
var personObject = JSON.parse(jsonPerson); //parse json string into JS object
Posted by: Guest on July-23-2019
44

convert fetch data to json

fetch("localhost:3000/api/home") // first step
  .then(response => response.json()) // second step
  .then(data => {
    console.log(data)
  })
  .catch(error => console.error(error))
Posted by: Guest on October-08-2021
12

javascript parse json

const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);
Posted by: Guest on May-20-2020
1

get jsonp with fetch

fetchJsonp('/users.jsonp')
  .then(function(response) {
    return response.json()
  }).then(function(json) {
    console.log('parsed json', json)
  }).catch(function(ex) {
    console.log('parsing failed', ex)
  })
Posted by: Guest on September-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language