Created
July 14, 2024 03:12
-
-
Save ndc/65237ed723fd3e76f86c74bc43a92948 to your computer and use it in GitHub Desktop.
Read JSON from file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Read JSON from file</title> | |
</head> | |
<body> | |
<form method="post" enctype="multipart/form-data" id="theform"> | |
<input type="file" id="fileinput"> | |
<button type="submit">Read</button> | |
</form> | |
<textarea id="theoutput" cols="120" rows="30"></textarea> | |
<script type="module"> | |
document.getElementById("theform").addEventListener("submit", readjson); | |
function readjson(ev) { | |
ev.preventDefault(); | |
const fileinput = document.getElementById("fileinput"); | |
const reader = new FileReader(); | |
reader.addEventListener("load", manipulateJSON); | |
reader.readAsText(fileinput.files[0]); | |
} | |
function manipulateJSON(ev) { | |
const thejson = JSON.parse(ev.target.result); | |
// put breakpoint here to manipulate the JSON in the debugger | |
const theoutput = thejson.data.list.members_timeline.timeline.instructions[1].entries | |
.filter(e => !!e.content.itemContent) | |
.map(e => e.content.itemContent.user_results.result.legacy.screen_name) | |
.join("\n"); | |
document.getElementById("theoutput").value = theoutput; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment