sample.js
const obj = {
obj1: "1111",
obj2: "1111",
obj3: "1111",
obj4: {
obj1: "1111",
obj2: "1111",
},
};
objToStr(obj);
function objToStr(sampleObj){
const s_Json = JSON.stringify(sampleObj, null, 2);
const line = s_Json.split('\n');
line.forEach(function (val) {
let keyAndValue = val.split(':');
let left = keyAndValue[0].replace(/"/m, '');
left = left.replace(/"/m, '');
const right = keyAndValue[1] ? ':' + keyAndValue[1] : '';
console.log(left + right + '\n');
});
}
実行結果
{
obj1: \"1111\",
obj2: \"1111\",
obj3: \"1111\",
obj4: {
obj1: \"1111\",
obj2: \"1111\"
}
}