Assuming you don't know which properties are JSON, you could use the replacer function parameter on JSON.stringify to check if a value is a JSON string. The below example tries to parse each string inside a try..catch , so is not the most efficient, but should do the trick (on nested properties as well)

var obj = {id:1, options:"{\"code\":3,\"type\":\"AES\"}"};

function checkVal(key,val){
	if(typeof val === 'string'){
		try{return JSON.parse(val);}catch(e){}
  }
  return val;
}

var res = JSON.stringify(obj,checkVal);

console.log('normal output', JSON.stringify(obj))
console.log('with replacer', res);

Answer from Me.Name on Stack Overflow
🌐
Built In
builtin.com › software-engineering-perspectives › json-stringify
How to Use JSON.stringify() and JSON.parse() in JavaScript | Built In
const user = { id: 101010, name: "Derek", email: "[email protected]" }; function replacer(key, value) { if (typeof value === "number") { return undefined; } if (key === "email") { return "Removed for privacy"; } return value; } console.log(JSON.stringify(user)); // result: {"id":101010,"name":"Derek","email":"[email protected]"} console.log(JSON.stringify(user, replacer)); // {"name":"Derek","email":"Removed for privacy"} console.log(JSON.stringify(user, null, "^_^ ")); // result: { // ^_^ "id": 101010, // ^_^ "name": "Derek", // ^_^ "email": "[email protected]" // } console.log(JSON.parse(JSO
🌐
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. Let me show you an example:
Discussions

JSON stringify objects with json strings already as values
Assuming you don't know which properties are JSON, you could use the replacer function parameter on JSON.stringify to check if a value is a JSON string. The below example tries to parse each string inside a try..catch , so is not the most efficient, but should do the trick (on nested properties ... More on stackoverflow.com
🌐 stackoverflow.com
.net core - How to stringify/normalize json in C# like JSON.stringify() would - Stack Overflow
There can be cases in C# too where ... to be in stringified form regardless. ... What do you mean by "normalize"? What is the reason you deserialize a json string and then immediately serialize it back to how it started? Is it just the quoting? ... @Crowcoder The example I have there ... More on stackoverflow.com
🌐 stackoverflow.com
TIP: How to Get Readable Format from JSON.stringify() - Tips & Tutorials - Keyboard Maestro Discourse
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. So, here is an example. JavaScript JSON.stringify Options //--- NORMAL, COMPACT, JSON.stringify() ... More on forum.keyboardmaestro.com
🌐 forum.keyboardmaestro.com
1
March 20, 2017
JSON Stringify for some fields
Hello, I have a multidimensional JSON that I map with a google sheets. For the 1st level, I map it normally For the 2nd level, I’d like to take the JSON as a string and put it in the Sheets field as is For example name → name field website → website field about → about field (with subtree ... More on community.make.com
🌐 community.make.com
1
0
March 3, 2024
🌐
DhiWise
dhiwise.com › post › javascript-essentials-detailed-exploration-of-json-stringify
Exploring JSON Stringify: An In-Depth Exploration
September 29, 2023 - JSON Stringify's space option is used to inject white space into the output JSON string for readability. It's an optional parameter that can be a number (from 0 to 10) or a string (up to 10 characters). Here's an example of using the space parameter to pretty print JSON:
🌐
Udacity
udacity.com › blog › 2021 › 04 › javascript-json-stringify.html
Converting Javascript Objects into Strings with JSON.stringify() | Udacity
September 27, 2022 - You can only use the white space parameter if you have defined a replacer function as well. Assuming a Javascript object called “object” and a replacer function called “replacer,” the following examples show valid JSON.stringify() calls including the white space parameter.
🌐
Scaler
scaler.com › home › topics › javascript json stringify() method
JavaScript JSON stringify() Method - Scaler Topics
May 4, 2023 - Let us look at an example. ... When defined as a string, the JSON stringify method uses that string in between adjacent keys, instead of space. The thing to note here is that the maximum length of the string acceptable is 10.
🌐
RestfulAPI
restfulapi.net › home › json › json stringify()
JSON stringify()
November 3, 2023 - var unmaskedData = { "name":"Lokesh", "accountNumber":"3044444444", "city":"New York"}; var maskedData = JSON.stringify( unmaskedData, maskInfo ); function maskInfo (key, value) { var maskedValue = value; if (key == "accountNumber") { if(value && value.length > 5) { maskedValue = "*" + maskedValue.substring(value.length - 4, value.length); } else { maskedValue = "****"; } } return maskedValue; } Program output. { "name": "Lokesh", "accountNumber": "*4444", //Masked account number "city": "New York" } ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-json-stringify-method
JavaScript JSON stringify() Method - GeeksforGeeks
July 11, 2025 - This argument is used to control ... the JSON.stringify() function. It can be a number or a string if it is a number then the specified number of spaces are indented to the final string and if it is a string then that string is (up to 10 characters) used for indentation. Return Value: Returns a string for a given value. Example 1: Converting ...
Top answer
1 of 2
11

The problem is that you are comparing having an OBJECT in JS then convert it to JSON, to having a STRING in C# and then convert it to JSON.

If you had a C# object, the equivalent to JSON.stringify() would be just JsonConvert.SerializeObject(myObject). C# doesn't accept JSON syntax (like JS does) to define an object.

On the MDN samples you posted, you see:

console.log(JSON.stringify({ x: 5, y: 6 }));

The c# equivalent would be (run it):

 Console.WriteLine(JsonConvert.SerializeObject(new { x = 5, y = 6 });

But that's just the way C# syntax works (Javascript allows JSON to define objects without having to parse them... C# has a different syntax for defining objects inline -anonymous or not-).

The equivalent in Javascript to the example you posted (having a string, and not an object) would be:

const jsString = '{"test": "test"}';
console.log(JSON.stringify(JSON.parse(jsString)));

Which is a bit different than just using JSON.stringify(), and matches what you are seeing in C# (deserializing then serializing)

Notice also that the syntax Javascript allows to define objects is not necessarily "strict valid JSON"... the above with this string would fail:

const jsString = '{ test: "test" }';

Whereas this way to define an object would be valid:

const jsObject = { test: "test" };

(that's, in fact, the reason you might want to "normalize" it as you call it)


All that said

if deserializing/serializing is a problem as in "looks", just make an extension method... something like:

public static string NormalizeJson(this string input) {
   return JsonConvert.SerializeObject(JsonConvert.DeserializeObject<object>(input));
}

And then you can just do this on any string (if you have added the using on top):

myJsonInput.NormalizeJson();

See it in action

2 of 2
-1

i think you missed formatting, it could be

public static string NormalizeJson(this string value)
{
  return JsonConvert.SerializeObject(JsonConvert.DeserializeObject<object>(value), Newtonsoft.Json.Formatting.Indented);
}
🌐
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 - Boolean, number, and string objects are converted to the corresponding primitive values during stringification; in accordance with the traditional conversion semantics. If a function, undefined, or a symbol is encountered during conversion, it is either omitted (when it is found in an object) or censored to null (when it is found in an array). JSON.stringify() also returns undefined when passing in "pure" values, such as JSON.stringify(function(){}) or JSON.stringify(undefined).
🌐
Keyboard Maestro
forum.keyboardmaestro.com › tips & tutorials
TIP: How to Get Readable Format from JSON.stringify() - Tips & Tutorials - Keyboard Maestro Discourse
March 20, 2017 - 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. So, here is an example. JavaScript JSON.stringify Options //--- NORMAL, COMPACT, JSON.stringify() ...
🌐
W3Schools
w3schools.com › js › js_json_stringify.asp
JSON.stringify()
Use the JavaScript function JSON.stringify() to convert it into a string.
🌐
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 a string or number (can be either a primitive or a wrapper object) — for example, is null or not provided — no white space is used. A JSON string representing the given value, or undefined. ... A BigInt value is encountered. JSON.stringify() converts a value to the JSON notation that the value represents.
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-json-parse-stringify
How To Use JSON.parse() and JSON.stringify() | DigitalOcean
November 24, 2021 - Please make the following change to correct the “stringify” demonstration, example code: let userObj = { name: “Sammy”, email: “sammy@example.com”, plan: “Pro” }; let userStrSpace = JSON.stringify(userObj , null, ‘…’); //**note change here.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
JSON methods, toJSON
January 24, 2024 - The method JSON.stringify(student) takes the object and converts it into a string.
🌐
npm
npmjs.com › package › fast-json-stringify
fast-json-stringify - npm
1 month ago - FJS creation x 9,696 ops/sec ±0.77% (94 runs sampled) CJS creation x 197,267 ops/sec ±0.22% (95 runs sampled) AJV Serialize creation x 48,302,927 ops/sec ±2.09% (90 runs sampled) json-accelerator creation x 668,430 ops/sec ±0.43% (95 runs sampled) JSON.stringify array x 7,924 ops/sec ±0.11% (98 runs sampled) fast-json-stringify array default x 7,183 ops/sec ±0.09% (97 runs sampled) json-accelerator array x 5,762 ops/sec ±0.27% (99 runs sampled) fast-json-stringify array json-stringify x 7,171 ops/sec ±0.17% (97 runs sampled) compile-json-stringify array x 6,889 ops/sec ±0.41% (96 runs
      » npm install fast-json-stringify
    
Published   Feb 06, 2026
Version   6.3.0
Author   Matteo Collina
🌐
The Code Barbarian
thecodebarbarian.com › the-80-20-guide-to-json-stringify-in-javascript.html
The 80/20 Guide to JSON.stringify in JavaScript | www.thecodebarbarian.com
May 28, 2019 - For example, suppose you wanted to omit all keys that contain the substring 'password': const obj = { name: 'Jean-Luc Picard', password: 'stargazer', nested: { hashedPassword: 'c3RhcmdhemVy' } }; // '{"name":"Jean-Luc Picard","nested":{}}' ...