[英]Rename json Object name in node.js
How do I rename Object name from Cars to automobiles? 如何将对象名称从汽车重命名为汽车? I tried using ObjectRenameKeys but it works on the properties within objects not the object name itself.
我尝试使用ObjectRenameKeys,但它适用于对象内的属性,而不适用于对象名本身。
Original: 原版的:
"Cars": [
{
"Part": 1
},
{
"Part": 2
},
{
"Part": 3
}
],
Expected:
"Automobiles": [
{
"Part": 1
},
{
"Part": 2
},
{
"Part": 3
}
],
You can't really rename properties....just copy Cars and then delete it: 您不能真正重命名属性...。只需复制Cars然后将其删除:
myObject.Automobiles = myObject.Cars;
delete myObject.Cars;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.