I searched everywhere but couldn't find a suitable code. So I decided to coded it myself. This is the best code/solution.
Kod:
function objToJson(obj) {
var json = "{";
for (const [index, value] of Object.entries(obj)) {
if (index != null && value != null) {
if (typeof(value) === "object") {
arrValue = objToJson(value);
console.log(arrValue);
json += '"' + index + '":' + arrValue + ',';
} else {
json += '"' + index + '":"' + value + '",';
}
}
}
if (json.charAt(json.length - 1) == ',')
json = json.slice(0, -1);
json += "}";
return json;
}
Son düzenleme: