<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>json stringify demo</title>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>Stringify Example: </h1>
</body>
</html>
$(function() {
$("h1").animate({
"margin-left": "200px"
}, "slow");
var cities = ['Miami', 'Orlando', 'Los Angeles', 'New York', 'Chicago'];
var json = JSON.stringify(cities);
console.log(json);
//------------------------------------------------------------------------------
const person = {
firstName: 'Paul',
lastName: 'Johnson',
age: 50,
jobTitle: 'Manager'
}
json = JSON.stringify(person);
//JavaScript Object Conversion
console.log(json);
//------------------------------------------------------------------------------
const book = {
title: 'JSON Stringify Example',
description: 'Providing great example on how to use JSON stringify',
year: '2020',
isOverdue: function() {
// code here
},
credits: new Map([
['Jacque Roma'],
['Darline Raroule']
])
}
//Working with Unsupported DataTypes
json = JSON.stringify(book);
console.log(json);
//------------------------------------------------------------------------------
function replacer(key, value) {
if (value < 1000) {
return undefined;
}
return value;
}
//Space argument
var reviews = {
books: 5000,
cars: 3000,
house: 999,
boat: 2000
};
//using a function as replacer
json = JSON.stringify(reviews, replacer);
console.log(json);
//using replacer as array
json = JSON.stringify(reviews, ['books', 'house','boat']);
console.log(json);
//using number as the third argument
json = JSON.stringify(reviews, ['books', 'house','boat'], 2);
console.log(json);
//using string as the third argument
json = JSON.stringify(reviews, ['books', 'house','boat'], 'xx');
console.log(json);
});
/* Styles go here */
.selected{
background-color:#f5f5f5;
}
.disable-link {
pointer-events: none;
cursor: default;
}