0

I am trying to access a single data from a JSON file with the url 'https://123.abc.com/student'. I need to display an individual data from this URL. Could someone help me with this?

My Json data looks like this

{"students":[{"_id":"5dc516e51bdd2c0014e32e65","name":"John","email":"[email protected]","mobile":"9988776655","__v":0},{"_id":"5dc517b51bdd2c0014e32e69","name":"Mark","email":"[email protected]","mobile":"9834783927","__v":0},{"_id":"5dca9231cfba5c0014d3d765","name":"Glen","email":"[email protected]","mobile":"9996474563","__v":0},{"_id":"5dcb898b9327cb00142169bb","name":"vijay","email":"[email protected]","mobile":"9884699633","__v":0},{"_id":"5dcb89c09327cb00142169bc","name":"tests","email":"[email protected]","mobile":"9887456123","__v":0},{"_id":"5dcb8caa9327cb00142169bd","name":"greens","email":"[email protected]","mobile":"9876543210","__v":0},{"_id":"5dcb95d69327cb00142169be","name":"Akash","email":"[email protected]","mobile":"9846042118","__v":0},{"_id":"5dcb961c9327cb00142169bf","name":"Akash K M","email":"[email protected]","mobile":"9846042118","__v":0},{"_id":"5dcce611ad69f500149660d5","name":"efavewbvwevb","email":"[email protected]","mobile":"9042758563","__v":0},{"_id":"5dcce874ad69f500149660d6","name":"efavewbvwevb","email":"[email protected]","mobile":"9042758563","__v":0},{"_id":"5dcce968ad69f500149660d7","name":"indrajit","email":"[email protected]","mobile":"9042758563","__v":0}]}

2 Answers 2

1

Accessing single and array of data

let data = {"students":[{"_id":"5dc516e51bdd2c0014e32e65","name":"John","email":"[email protected]","mobile":"9988776655","__v":0},{"_id":"5dc517b51bdd2c0014e32e69","name":"Mark","email":"[email protected]","mobile":"9834783927","__v":0},{"_id":"5dca9231cfba5c0014d3d765","name":"Glen","email":"[email protected]","mobile":"9996474563","__v":0},{"_id":"5dcb898b9327cb00142169bb","name":"vijay","email":"[email protected]","mobile":"9884699633","__v":0},{"_id":"5dcb89c09327cb00142169bc","name":"tests","email":"[email protected]","mobile":"9887456123","__v":0},{"_id":"5dcb8caa9327cb00142169bd","name":"greens","email":"[email protected]","mobile":"9876543210","__v":0},{"_id":"5dcb95d69327cb00142169be","name":"Akash","email":"[email protected]","mobile":"9846042118","__v":0},{"_id":"5dcb961c9327cb00142169bf","name":"Akash K M","email":"[email protected]","mobile":"9846042118","__v":0},{"_id":"5dcce611ad69f500149660d5","name":"efavewbvwevb","email":"[email protected]","mobile":"9042758563","__v":0},{"_id":"5dcce874ad69f500149660d6","name":"efavewbvwevb","email":"[email protected]","mobile":"9042758563","__v":0},{"_id":"5dcce968ad69f500149660d7","name":"indrajit","email":"[email protected]","mobile":"9042758563","__v":0}]}

//access name
console.log('name--', data.students[0].name)

//single object
console.log(data.students[0])

//access array of objects
data.students.map(d=> console.log(d))

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks @vahid , could you help me on how to view it as a URL?
@IndrajitRavi can you explain little more how you want... i didn't get you as URL means what? ...you want to fetch from URL?
Sorry Im completely new to this. I get the Json data from an url, now if i want to view only one data on the browser say for example '123.abc.com/student/students[0]'
@IndrajitRavi no bro you can't access like this because it's backend api and for single object you need that api to access... in UI you can access like i posted
1

You can use this

let data = {"students":[{"_id":"5dc516e51bdd2c0014e32e65","name":"John","email":"[email protected]","mobile":"9988776655","__v":0},{"_id":"5dc517b51bdd2c0014e32e69","name":"Mark","email":"[email protected]","mobile":"9834783927","__v":0},{"_id":"5dca9231cfba5c0014d3d765","name":"Glen","email":"[email protected]","mobile":"9996474563","__v":0},{"_id":"5dcb898b9327cb00142169bb","name":"vijay","email":"[email protected]","mobile":"9884699633","__v":0},{"_id":"5dcb89c09327cb00142169bc","name":"tests","email":"[email protected]","mobile":"9887456123","__v":0},{"_id":"5dcb8caa9327cb00142169bd","name":"greens","email":"[email protected]","mobile":"9876543210","__v":0},{"_id":"5dcb95d69327cb00142169be","name":"Akash","email":"[email protected]","mobile":"9846042118","__v":0},{"_id":"5dcb961c9327cb00142169bf","name":"Akash K M","email":"[email protected]","mobile":"9846042118","__v":0},{"_id":"5dcce611ad69f500149660d5","name":"efavewbvwevb","email":"[email protected]","mobile":"9042758563","__v":0},{"_id":"5dcce874ad69f500149660d6","name":"efavewbvwevb","email":"[email protected]","mobile":"9042758563","__v":0},{"_id":"5dcce968ad69f500149660d7","name":"indrajit","email":"[email protected]","mobile":"9042758563","__v":0}]}

let result = data.students.forEach(val=>{
  console.log(val)
  // let data individually as 
  let name = val.name 
  let email = val.email 
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.