在Redfish输出中使用jq检索@ odata.id的值

时间:2020-01-29 01:20:52

标签: json jq

我正在使用jq解析一些json Redfish数据。

尝试从下面的redfish.txt文件中提取@ odata.id的值。

使用推荐的jq调用[“ @ odata.id”]似乎并不能完全发挥自身的价值,即/ redfish / v1 / Systems

欢迎任何建议。输出如下...:)

谢谢, 尼克

root@ubuntu-xenial:/var/opt# cat redfish.txt
{"@odata.context":"/redfish/v1/$metadata#ServiceRoot.ServiceRoot","@odata.id":"/redfish/v1","@odata.type":"#ServiceRoot.v1_2_0.ServiceRoot","AccountService":{"@odata.id":"/redfish/v1/Managers/iDRAC.Embedded.1/AccountService"},"Chassis":{"@odata.id":"/redfish/v1/Chassis"},"Description":"Root Service","EventService":{"@odata.id":"/redfish/v1/EventService"},"Id":"RootService","JsonSchemas":{"@odata.id":"/redfish/v1/JSONSchemas"},"Links":{"Sessions":{"@odata.id":"/redfish/v1/Sessions"}},"Managers":{"@odata.id":"/redfish/v1/Managers"},"Name":"Root Service","Oem":{"Dell":{"@odata.type":"#DellServiceRoot.v1_0_0.ServiceRootSummary","IsBranded":0,"ManagerMACAddress":"d0:96:69:51:d4:70","ServiceTag":"XXXX"}},"RedfishVersion":"1.2.0","Registries":{"@odata.id":"/redfish/v1/Registries"},"SessionService":{"@odata.id":"/redfish/v1/SessionService"},"Systems":{"@odata.id":"/redfish/v1/Systems"},"Tasks":{"@odata.id":"/redfish/v1/TaskService"},"UpdateService":{"@odata.id":"/redfish/v1/UpdateService"}}
root@ubuntu-xenial:/var/opt# cat redfish.txt | jq .Systems
{
  "@odata.id": "/redfish/v1/Systems"
}
root@ubuntu-xenial:/var/opt# cat redfish.txt | jq .Systems | jq .@odata.id
jq: error: syntax error, unexpected FIELD, expecting QQSTRING_START (Unix shell quoting issues?) at <top-level>, line 1:
.@odata.id
jq: error: try .["field"] instead of .field for unusually named fields at <top-level>, line 1:
.@odata.id
jq: 2 compile errors
root@ubuntu-xenial:/var/opt# cat redfish.txt | jq .Systems | jq .["@odata.id"]
{
  "@odata.id": "/redfish/v1/Systems"
}
"/redfish/v1/Systems"
root@ubuntu-xenial:/var/opt# cat redfish.txt | jq .Systems | jq .["odata.id"]
{
  "@odata.id": "/redfish/v1/Systems"
}
"/redfish/v1/Systems"
root@ubuntu-xenial:/var/opt#

1 个答案:

答案 0 :(得分:0)

您可以简单地使用过滤器:

vue-loader

也就是说,在bash或类似bash的提示符下,您将输入以下内容:

.Systems["@odata.id"]