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
- Import "django.shortcuts" could not be resolved from source in Django Project
- How to add two numbers in Android Studio? | Source Code
- FindViewByID returns null in android studio -SOLVED
- Saving changes is not permitted in SQL SERVER - [SOLVED]
- Restore of database failed. File cannot be restored over the existing. -[SOLVED]
- One or more projects in the solution were not loaded correctly in Visual Studio 2019 | FIXED
- How to find Laptop's Battery Health?
- SOLVED-Related Field got invalid lookup: icontains error in Django
Related Article