我有一个脚本
的以下输出{"emeter":{"get_realtime":{"current":0.501730,"voltage":240.819788,"power":70.455025,"total":1.798000,"err_code":0}}}
我需要将它转换为prometheus exporter collector的格式:
current 0.53
voltage 234
power 84.04
total 0.92
建议?
答案 0 :(得分:0)
my_obj
是您的对象Object.keys()
filter
Array
方法
var my_obj = {
"emeter": {
"get_realtime": {
"current": 0.501730,
"voltage": 240.819788,
"power": 70.455025,
"total": 1.798000,
"err_code": 0
}
}
}
var inner = my_obj.emeter.get_realtime;
var innerKeys = Object.keys(inner);
innerKeys.filter(k => k !== "err_code")
.forEach(k => console.log(k, inner[k]));