JSON stands for javascript Object Notation. It is a light weight data interchange format. It is easier to handle and alternative to XML.
Creating a JSON object:
Creating Json is a format based on the structure of JavaScript Object declaration. Here we are creating product data that can be stored to json object as shown below.
JSON.Stringify () method used to convert JavaScript to JSON string.
Example:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var ProductJSON = [
{
"ProductName": "computer",
"Code": "ED002",
"Price": 500,
"ProductType": "electronic"
},
{
"ProductName": "Chair",
"Code": "D5695",
"Price": 1500,
"ProductType": "furniture"
}
];
var JSONString = JSON.stringify(ProductJSON);
$('#resultDiv').html(JSONString);
});
</script>
</head>
<body style="font-family:Arial">
<div id="resultDiv"></div>
</body>
</html>
Output:
[{"ProductName":"computer","Code":"ED002","Price":500,"ProductType":"electronic"},{"ProductName":"Chair","Code":"D5695","Price":1500,"ProductType":"furniture"}]
Post your comments / questions
Recent Article
- How to get domain name information from a Domain using Python
- ModulenotFoundError: no module named 'debug_toolbar' -SOLUTION
- How to create superuser in django project hosted in cPanel without terminal
- CSS & images not loading in django admin | cpanel without terminal
- Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
- How to sell domain name on Godaddy (2023)
- TemplateSyntaxError at / Could not parse the remainder: ' + 1' from 'forloop.counter0 + 1'
- urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0
Related Article