This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

JSON.stringify() will remove any functions from an object.

Convert functions into strings to keep them in the JSON object.

// create JavaScript object with an "age" function
const obj = {name: "John", age: function () {return 30;}, city: "New York"};

// convert "age: function () {return 30;}" to a JS string
obj.age = obj.age.toString();

// create JSON string
const myJSON = JSON.stringify(obj);
document.getElementById("demo").innerHTML = myJSON;