There is a way to serialize a function in JS, but you'll have to eval it on the other side and it will also lose access to it's original scope. A way to do it would be:

JSON.stringify(objWithFunction, function(key, val) {
  if (typeof val === 'function') {
    return val + ''; // implicitly `toString` it
  }
  return val;
});

There are some legitimate uses for what you're asking despite what people are posting here, however, it all depends on what you're going to be using this for. There may be a better way of going about whatever it is you're trying to do.

Answer from chjj on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › stringify
JSON.stringify() - JavaScript | MDN
If space is anything other than ... the given value, or undefined. ... A BigInt value is encountered. JSON.stringify() converts a value to the JSON notation that the value represents....
🌐
W3Schools
w3schools.com › js › js_json_stringify.asp
JSON.stringify()
JSON.stringify() can not only convert objects and arrays into JSON strings, it can convert any JavaScript value into a string.
Discussions

javascript - JSON.stringify function - Stack Overflow
In fact, It's very easy to serealize / parse javascript object with methods. Take a look at JSONfn plugin. ... doesnt stringify getter setter, also when it returns type of object said to be some kind of Object, not the Type i had defined before... More on stackoverflow.com
🌐 stackoverflow.com
javascript - JSON stringify a Set - Stack Overflow
For anyone else coming here later ... this, JSON.parse takes an equivalent function called reviver that's run on everything it parses. I ended up solving this by adding "__isSet" to the start of any array made out of a set and then checking for this in the reviver function, turning it back into a set when found. 2023-04-26T00:29:40.077Z+00:00 ... While all of the above work I suggest that you subclass set and add a toJSON method to make sure that it stringify's ... More on stackoverflow.com
🌐 stackoverflow.com
[AskJS] PETITION: Make JSON.stringify use any object's toString method internally!
.toJSON already exists, it's just a not well known feature of JS. 6th bullet point. More on reddit.com
🌐 r/javascript
16
0
January 3, 2024
JSON Stringify and JSON objects with JS functions
I am trying to convert an object in 4D into an object for use in javascript. Specifically i have some code like this. var $oColumn:Object $oColumn:=New Object() $oColumn.columnName:="active" $oColumn.render:="function(data, type, row) {alert('hello world')}" $vtReturn:=JSON Stringify($oColumn) ... More on discuss.4d.com
🌐 discuss.4d.com
0
May 28, 2024
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-json-stringify-method
JavaScript JSON stringify() Method - GeeksforGeeks
July 11, 2025 - The JSON.stringify() method in JavaScript is used to convert JavaScript objects into a JSON string.
🌐
V8
v8.dev › blog › json-stringify
How we made JSON.stringify more than twice as fast · V8
At the end, the final result is constructed by simply concatenating the output from the initial one-byte stringifier with the output from the two-byte one. This strategy ensures we stay on a highly-optimized path for the common case, while the transition to handling two-byte characters is lightweight and efficient. Any string in JavaScript can contain characters that require escaping when serializing to JSON (e.g.
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-json-parse-stringify
How To Use JSON.parse() and JSON.stringify() | DigitalOcean
November 24, 2021 - JSON.stringify() takes a JavaScript object and transforms it into a JSON string.
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › json-stringify-example-how-to-parse-a-json-object-with-javascript
JSON Stringify Example – How to Parse a JSON Object with JS
January 5, 2021 - Luckily, this works the same way as in the browser – just use JSON.stringify() to convert JavaScript object literals or arrays into a JSON string:
🌐
DhiWise
dhiwise.com › post › javascript-essentials-detailed-exploration-of-json-stringify
Exploring JSON Stringify: An In-Depth Exploration
September 29, 2023 - JSON Stringify is a method in JavaScript that converts JavaScript objects into JSON strings. Learn about JSON Stringify its syntax, and its parameters.
🌐
Medium
medium.com › @pmzubar › why-json-parse-json-stringify-is-a-bad-practice-to-clone-an-object-in-javascript-b28ac5e36521
Why use JSON “parse” and “stringify” methods a bad practice to clone objects in JavaScript (2023 update) | by Petro Zubar | Medium
October 10, 2023 - JSON.stringify({ key: undefined }); // converted to "{}" JSON.stringify({ key: Symbol() }); // "{}" again JSON.stringify({ key: function(){} }); // "{}" as well · As you can see, you can just lose data of unsupported types when copying your object in such a way. Moreover, JavaScript won`t even warn you about that, because calling JSON.stringify() with such data types does not throw any error.
🌐
Medium
mahabub-r.medium.com › how-json-stringify-and-json-parse-f455dae70619
How JSON.stringify() and JSON.parse() Work Behind the Scenes — and How to Handle Complex JavaScript Data | by Mahabubur Rahman | Medium
May 22, 2025 - When working with JavaScript, JSON.stringify() and JSON.parse() are the go-to methods for converting objects into strings and back. They're critical for saving data in localStorage, sending it over the network, or persisting it in files.
🌐
Udacity
udacity.com › blog › 2021 › 04 › javascript-json-stringify.html
Converting Javascript Objects into Strings with JSON.stringify() | Udacity
September 27, 2022 - JSON.stringify() requires one parameter: the Javascript object to be converted into a JSON string. Javascript object literals can be cumbersome to type, so it is often easier and more readable to pass them as a variable.
🌐
ServiceNow Community
servicenow.com › community › developer-articles › json-stringify-making-json-look-pretty-and-perfect › ta-p › 2534944
JSON.stringify() - Making JSON Look Pretty and Per... - ServiceNow Community
December 9, 2025 - You can even copy and paste it into a code editor or online tool for even easier readability. But wait, there's more! JSON.stringify() has many use cases beyond just making your code look pretty. For instance, if you're working with APIs, you can use it to convert your JSON object into a string that can be sent as a request.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
JSON methods, toJSON
The method JSON.stringify(student) takes the object and converts it into a string.
🌐
Reddit
reddit.com › r/javascript › [askjs] petition: make json.stringify use any object's tostring method internally!
Make JSON.stringify use any object's toString method ...
January 3, 2024 -

What do you guys think? Should I make an official proposal? What would be the best way to make such spec proposal?

And tell me what you think! The idea is for any object's toString method override the way JSON.stringify creates the string. For example:

var vec =
{
    x: 0,
    y: 0,
    toString() => `[${this.x},${this.y}]`
}

JSON.stringify(vec) //will return: '[0,0]'

This way I won't need to use a custom stream to alter a big object when converting it to JSON!

Or would you say this is very unnecessary, even if an easy thing to add to JS?

🌐
Medium
medium.com › @debbie.obrien › json-parse-v-json-stringify-4b9d104c78d0
JSON Parse v JSON Stringify. I always get confused between the JSON… | by Debbie O'Brien | Medium
May 28, 2018 - The JQuery SerializeArray() method creates an array of obejcts by serializing form values. It is very similar to the serialize() method but returns a JSON data structure. This is returned not as a string and if you needed it to be a string you ...
🌐
W3Schools
w3schools.com › jsref › jsref_stringify.asp
JavaScript JSON stringify() Method
Stringify a JavaScript object: ... » · More "Try it Yourself" examples below. The JSON.stringify() method converts JavaScript objects into strings....
🌐
4D
discuss.4d.com › english community
JSON Stringify and JSON objects with JS functions - English Community - 4D Forum
May 28, 2024 - I am trying to convert an object in 4D into an object for use in javascript. Specifically i have some code like this. var $oColumn:Object $oColumn:=New Object() $oColumn.columnName:="active" $oColumn.render:="function(data, type, row) {alert('hello world')}" $vtReturn:=JSON Stringify($oColumn) ...