How to keep the spaces in the object when js converts strings?

var params = {"type": "1", 
              "value": "2"}
var str  = JSON.stringify(params);

str outputs"{"type": "1", "value": "2"}", and the original space is removed;
if you want to keep the space after the colon, output"{"type": "1", "value": "2"}", is there any good way besides the repalce method?

Sep.16,2021

JSON.stringify(params, '', 1);


try to see if the JSON transferred out in this way is what you want. You define the object, and it is impossible to leave spaces directly unless you directly define the JSON string

.

JSON.stringify can receive three parameters

JSON.stringify(value[, replacer[, space]])

it is impossible to keep spaces. The spaces in json are meaningless. Any compression tool will drop these Filter

.

but it can have an effect similar to formatting code

for example,

JSON.stringify(data,null,'\t');
//

JSON.stringify(data,null,2);
//2
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea87a8-4695d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea87a8-4695d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?