JSON.stringify doesn't directly work with sets because the data stored in the set is not stored as properties.

But you can convert the set to an array. Then you will be able to stringify it properly.

Any of the following will do the trick:

JSON.stringify([...s]);
JSON.stringify([...s.keys()]);
JSON.stringify([...s.values()]);
JSON.stringify(Array.from(s));
JSON.stringify(Array.from(s.keys()));
JSON.stringify(Array.from(s.values()));
Answer from Oriol on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › stringify
JSON.stringify() - JavaScript | MDN
The JSON.stringify() static method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.
🌐
JSON Formatter
jsonformatter.org › json-stringify-online
JSON Stringify Online using JSON.Stringify()
JSON Stringify Online is very unique tool for convert JOSN to String and allows to download, save, share and print JSON to TSV data..
Discussions

JSON stringify a Set
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
JSON.stringify function
Is there any way to stringify and object and maintain the methods it has? ... It will be added to a onclick event, please see the comment I left at David's answer below. ... 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... More on stackoverflow.com
🌐 stackoverflow.com
TIP: How to Get Readable Format from JSON.stringify() - Tips & Tutorials - Keyboard Maestro Discourse
TIP: How to Get Readable Format from JSON.stringify() I suspect most of you JavaScript and JavaScript for Automation (JXA) scripters are at least somewhat familiar with the powerful JSON functions, like JSON.stringify() - JavaScript | MDN. However, some of you, like me, may not be aware of ... More on forum.keyboardmaestro.com
🌐 forum.keyboardmaestro.com
1
March 20, 2017
Json stringify
Hello, related to the last question I have a doubt using JSON.stringify I have a database, with multiple cells, and under each cell, values. Cells are: id, name, duration, date, and relationid In this database I have … More on sitepoint.com
🌐 sitepoint.com
0
July 6, 2018
🌐
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.
🌐
JSONLint
jsonlint.com › json-stringify
JSON Stringify - Escape JSON for Embedding | JSONLint | JSONLint
JSON Stringify converts a JSON object into an escaped string. The result can be safely embedded inside another string—in code, databases, or even nested within other JSON.
🌐
ServiceNow Community
servicenow.com › community › developer-blog › servicenow-things-to-know-77-json-stringify-or-stringify-object › ba-p › 2783663
ServiceNow Things to Know 77: JSON.stringify() or ... - ServiceNow Community
January 8, 2024 - Explanation:- Creates a string from a JSON object. The JSON.stringify() method can only convert numbers, strings, and Java native objects to strings. It cannot convert user-defined objects to strings, unless those objects provide a toJSON() method. JSON.stringify() converts a value to JSON notat...
🌐
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.
Find elsewhere
🌐
Online Tools
onlinetools.com › json › stringify-json
Stringify JSON – Online JSON Tools
We call the JSON.stringify() function on the input data and it converts line breaks into "\n" escape sequences, quotes into "\"" escape sequences, and tabs into "\t" escape sequences.
🌐
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 - So, how do we use JSON.stringify()? It's actually quite simple. All you need is your JSON object and the stringify() method. And if you want to make it look even prettier, just add null and '\t' as the second and third parameters.
🌐
Execute Program
executeprogram.com › courses › modern-javascript › lessons › json-stringify-and-parse
Modern JavaScript: JSON Stringify and Parse
Learn programming languages like TypeScript, Python, JavaScript, SQL, and regular expressions. Interactive with real code examples.
🌐
Udacity
udacity.com › blog › javascript-json-stringify
Converting Javascript Objects into Strings with JSON.stringify() | Udacity
September 27, 2022 - JSON.stringify() converts Javascript objects into JSON strings. It can manage many types of data type conversion, and you can also add special conversions.
🌐
ServiceNow Community
servicenow.com › community › developer-articles › interesting-facts-about-json-stringify › ta-p › 2329985
Interesting facts about JSON.stringify() - ServiceNow Community
June 5, 2021 - We all know the primary purpose for JSON.stringify(), The JSON.stringify() method converts a JavaScript object or value to a JSON string. However there are 2 interesting parameter that can be used to simplify developer's job. One can be used to filter the JSON and other can be used to indent it.
🌐
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 - JSON.stringify() converts a JavaScript object to a JSON string. When sending data to a web server, the data has to be a string.
🌐
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 - And just like that, you've parsed incoming JSON with fetch and used JSON.stringify() to convert a JS object literal into a JSON string.
🌐
Rocketsoftware
m204wiki.rocketsoftware.com › index.php › Stringify_(Json_function)
Stringify (Json function) - m204wiki
August 23, 2016 - This function serializes a Json object tree as a unicode JSON string. ... The name Stringify derives from the equivalent JavaScript method: JSON.stringify.
🌐
Online String Tools
onlinestringtools.com › json-stringify-string
JSON Stringify a String – Online String Tools
This tool converts a string to a JSON string. This is done by calling JSON.stringify() function on the input string. This function adds double quotes at the beginning and end of the input string and escapes special JSON characters.
🌐
Keyboard Maestro
forum.keyboardmaestro.com › tips & tutorials
TIP: How to Get Readable Format from JSON.stringify() - Tips & Tutorials - Keyboard Maestro Discourse
March 20, 2017 - TIP: How to Get Readable Format from JSON.stringify() I suspect most of you JavaScript and JavaScript for Automation (JXA) scripters are at least somewhat familiar with the powerful JSON functions, like JSON.stringify() - JavaScript | MDN. However, some of you, like me, may not be aware of some options of the JSON.stringify() function to generate a very readable output, and to filter the output.
🌐
SitePoint
sitepoint.com › javascript
Json stringify
July 6, 2018 - Hello, related to the last question I have a doubt using JSON.stringify I have a database, with multiple cells, and under each cell, values. Cells are: id, name, duration, date, and relationid In this database I have 3 rows: I have this code: var result = {} properties.data.forEach(addToResult); //Get data from database using properties.data instance.data.datavarb = JSON.stringify(result); //Send data after converted to JSON function addToResult(pair,isjson){ //operations ...
🌐
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.