DEV Community

R.Shobika CSE
R.Shobika CSE

Posted on

JSON IN JS

JSON:

  • JSON means JavaScript Object Notation.

  • JSON is a Text Format for storing and exchanging data.

  • JSON is a array of object.

JSON format:

[ ------------------> ARRAY
{-----------> OBJECT1
----
----
},----------> OBJECT1
{-----------> OBJECT2
----
----
----
}-----------> OBJECT2
]-------------------> ARRAY
Enter fullscreen mode Exit fullscreen mode

API :

  • API means Application Programming Interface.

  • It build the communication between frontend and backend.

Fetch:

  • Fetch is a function we give the parameter as a data URL which means (JSON file)

  • This function return promise .

  • If the promise resolve means it will go to the .then function if it is resolve means again it will go to the the next .then function .

  • If the promise does not resolve means it will go to the .catch function

const api=fetch('https://fakestoreapi.com/products/1')
api.then(()=>console.log("success"))
   .catch(()=>console.log("rejected"))
Enter fullscreen mode Exit fullscreen mode

Output
success

if the URL have some mistake means it will go to .catch block

Top comments (0)