【发布时间】:2020-12-11 04:14:24
【问题描述】:
JSON 示例:
[
[
SERV1,
{
"QOS Script Version=Not Installed",
Host_Name=ABC,
IP Address=123.123.123.123,
Free Space=244Gi,
Time Ran=Sat Nov 31 07:26:02 +08 2020,
Backup Location= VOL03,
Date of Last Backup=2020-26-28-031839,
Last Reboot Time= Nov 18 02:00:13 2020,
Total Storage=1.8Ti,
OS Version=10.15.6
}
],
[
DATASTORE,
{
"QOS Script Version=Not Installed",
Date of Last Backup=2020-11-28-031520,
Free Space=34Gi,
IP Address=123.123.123.12,
OS Version=10.15.6,
Total Storage=1.8Ti,
Backup Location= VOL03,
Time Ran=Sat Nov 15 07:23:48 +08 2020,
Host_Name=ABC,
Last Reboot Time= Nov 28 02:04:21 2020
}
]
]
我需要以这种格式将其转储到谷歌表格中:
+-----------+-----------------+------------+-----------------+------+
| Server | Backup Location | Free Space | IP Address | etc. |
+-----------+-----------------+------------+-----------------+------+
| SERV1 | VOL03 | 244Gi | 123.123.123.123 | |
+-----------+-----------------+------------+-----------------+------+
| DATASTORE | VOL01 | 1.8Ti | 123.123.123.124 | |
+-----------+-----------------+------------+-----------------+------+
| etc. | | | | |
+-----------+-----------------+------------+-----------------+------+
列标题的顺序可以调整,列表按服务器的字母顺序排列。我曾尝试在此答案中使用代码,但出现错误“无法读取未定义的属性 'reduce'”:Parse Nested Json Data to Google Sheets with App Script
json 是使用这个 Firebase 库生成的:https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/tutorials/read-and-write-data-in-firebase-from-apps-script
var object = Object.entries(FirebaseApp.getDatabaseByUrl(url, optSecret).getData());
数据在“QOS 脚本版本”键周围有额外的空格和引号,它们可以保留在谷歌表中,但理想情况下会被删除。这最终将从原始的 firebase 源中删除,但我目前需要 google sheet 转储,但无法弄清楚如何以这种方式对其进行格式化。 感谢您提供的任何帮助。
【问题讨论】:
-
根据online validator,您的JSON无效
-
@Cooper 感谢您的帮助!我现在可以让它工作了