looking for some solutions? You are welcome.

SOLVED: Extract specific element from API-JSON File

Parth Patankar:

I am trying to extract File names from a JSON which is fetched using WEB API URL. I want to show only one item from that file. I am able to get full JSON on HTML page but not just one element.

My JSON File:

 {"FileStatuses":{"FileStatus":[{"accessTime":0,"blockSize":0,"childrenNum":1,"fileId":16386,"group":"supergroup","length":0,"modificationTime":1550036943240,"owner":"hduser1","pathSuffix":"new","permission":"755","replication":0,"storagePolicy":0,"type":"DIRECTORY"},{"accessTime":0,"blockSize":0,"childrenNum":0,"fileId":16473,"group":"supergroup","length":0,"modificationTime":1550055484183,"owner":"hduser1","pathSuffix":"pp2","permission":"755","replication":0,"storagePolicy":0,"type":"DIRECTORY"},{"accessTime":0,"blockSize":0,"childrenNum":1,"fileId":16388,"group":"supergroup","length":0,"modificationTime":1550037310909,"owner":"hduser1","pathSuffix":"tmp","permission":"700","replication":0,"storagePolicy":0,"type":"DIRECTORY"},{"accessTime":0,"blockSize":0,"childrenNum":1,"fileId":16475,"group":"supergroup","length":0,"modificationTime":1550055624446,"owner":"hduser1","pathSuffix":"weJ","permission":"755","replication":0,"storagePolicy":0,"type":"DIRECTORY"},{"accessTime":0,"blockSize":0,"childrenNum":1,"fileId":16471,"group":"supergroup","length":0,"modificationTime":1550125046426,"owner":"hduser1","pathSuffix":"webhdfs","permission":"755","replication":0,"storagePolicy":0,"type":"DIRECTORY"}]}}

I want to Extract Only PathSuffix from it and show it vertically.

My JS code:

var ourRequest = new XMLHttpRequest();
ourRequest.open('GET','http://localhost/webhdfs/v1/user.name=hduser&op=LISTSTATUS')
ourRequest.onload = function() {

    console.log(ourRequest.responseText);
    document.write(ourRequest.responseText);
};

ourRequest.send();

My HTML Code:

<html lang="en">
<head>
<script src=hmt.js></script>
</head>
<body>

<input type="button" id="btn" value="get result" >
</body>
</html>

Please tell me how to get only pathsuffix value on webpage on click. Thank you :)



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent