+ 7

accessing json file in javascript.

i am working with a news api, in which response.json() when printing in console gives correct output but when i try same for document it won't work it says its undefined i want to access the article array in response.json() but it wont work.. https://code.sololearn.com/Wb3Y5OP4RQ3R/?ref=app if you have any idea of how to parse this json object and access only particular part of that json plz tell me. thank you. {try it in console of chrome browser because that gives the feature of expanding the json object.} [ edit: equivalent python code is given below... trying the same for JavaScript https://code.sololearn.com/cgePJmjJp36H/?ref=app ]

21st Mar 2019, 3:12 PM
Aaditya Deshpande
Aaditya Deshpande - avatar
8 Answers
+ 7
Aaditaya Take a look at this[code I wrote for open APIs ] and let me know if you have any questions. Vanilla js displays data in the text area to show the layout of JSON. List name of authors for each article as an example. https://code.sololearn.com/WUN219pVaXPX/#html
21st Mar 2019, 5:25 PM
ODLNT
ODLNT - avatar
+ 7
Gordon information you provided is really helpful but i am trying to do it in vanilla JS.. & manipulating that JSON data is something i am trying to do... What data you loaded is more like a metadata 😅 i am interested in payload..😃
21st Mar 2019, 4:54 PM
Aaditya Deshpande
Aaditya Deshpande - avatar
+ 6
ODLNT thanks.. i was looking for the same..👍
21st Mar 2019, 5:37 PM
Aaditya Deshpande
Aaditya Deshpande - avatar
+ 5
Aaditya You're welcome. Keep an eye on that payload it can be filled with objects with arrays of objects 😉
21st Mar 2019, 5:49 PM
ODLNT
ODLNT - avatar
+ 5
Yes ODLNT i am dealing with the same right now.. 😅
21st Mar 2019, 5:52 PM
Aaditya Deshpande
Aaditya Deshpande - avatar
22nd Mar 2019, 10:55 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 3
Answer to your question 1: You applied json() method twice. Because you have use json() already, you should use the variable data later. https://code.sololearn.com/WgVK9msFUq03/?ref=app I'll come back for your question 2
21st Mar 2019, 3:28 PM
Gordon
Gordon - avatar
+ 3
1. A successful example: Code of the Day of Nikky: https://code.sololearn.com/W4wf3w9Sn0BY/?ref=app Ajax data is parameter of the success function. But it is in JQuery 2. For vanilla JS, it is something related to this : https://www.sololearn.com/learn/JavaScript/2981/ In a Promise, you have argument of a function with two functions as parameters, one to be executed at success, one to be executef at failure. 3. My current status: I should be quite close already. https://code.sololearn.com/WHs84VoxRLgP/?ref=app But I need to sleep now. But I know who can hp you: Morpheus
21st Mar 2019, 4:29 PM
Gordon
Gordon - avatar