Core JavaScript

Parsing JSON

This is an example program that shows how to parse a JSON string in JavaScript.

ParseJson.html

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width" />
		<title>XoaX.net's Javascript</title>
		<!-- Supply a transparent 1x1 favicon -->
		<link rel="icon" href="data:,">
		<script type="text/javascript" src="ParseJson.js"></script>
	</head>
	<body onload="Initialize()">
		<span id="idChurchFather"></span>
	</body>
</html>

ParseJson.js

function Initialize() {
	const sJsonText = '{ "Name": "Clement of Rome", "Year of Death": "A.D. 97", "Description": "The Fourth Pope" }';
	const qJsonObject = JSON.parse(sJsonText);
	
	document.getElementById("idChurchFather").innerHTML = 
		"Name: " + qJsonObject.Name + "<br />" +
		"Year of Death: " + qJsonObject["Year of Death"] + "<br />" +
		"Description: " + qJsonObject.Description;
}
 

Output

 
 

© 2007–2026 XoaX.net LLC. All rights reserved.