use of .json() in javascript 1

use of .json() in javascript

fetch('http://example.com/movies.json')
  .then(response => response.json())
  .then(data => console.log(data));
//Since the HTTP response is not a JSON Object, 
//.json() extracts the JSON Object from the HTTP response

Here is what the above code is Doing:
1. The fetch() method is called on the URL of the JSON file.
2. The response is passed to the .then() method.
3. The response is converted to a JSON object by the .json() method.
4. The JSON object is passed to the .then() method.
5. The JSON object is logged to the console.

Similar Posts