I try to get theses value :
"VmDisplayName, CreationTimeUTC, EndTimeUTC, Reason, Result, State, TotalSize, BackupServerReference, BackupJobSessionReference" from this json :
{
"JobSessionUid": "urn:veeam:BackupJobSession:fe8a7b44-5d5d-4767-e5f4-db0dba854c59",
"CreationTimeUTC": "2017-11-14T21:02:54Z",
"EndTimeUTC": "2017-11-14T21:03:30Z",
"State": "Completed",
"Result": "Success",
"Reason": "",
"TotalSize": 599785472,
"VmUid": "urn:VMware:Vm:11e45620-a0dc-1278-6d13-11a58ce70564.vm-1128",
"VmDisplayName": "VMName",
"Name": "VMName@2017-11-14 21:02:54",
"UID": "urn:veeam:BackupTaskSession:540c9985-52ab-ab01-a453-e0126edf8716",
"Links": [
{
"Rel": "Up",
"Href": "https://10.255.147.125:9398/api/backupServers/e435adc7-63f9-4115-be34-0a647e8faa1e",
"Name": "veeam-dcc-02",
"Type": "BackupServerReference"
},
{
"Rel": "Up",
"Href": "https://10.255.147.125:9398/api/backupSessions/fe8a7b44-5d5d-4767-e5f4-db0dba854c59",
"Name": "Backup Name@2017-11-14 21:00:02",
"Type": "BackupJobSessionReference"
},
{
"Rel": "Alternate",
"Href": "https://10.255.147.125:9398/api/backupTaskSessions/540c9985-52ab-ab01-a453-e0126edf8716",
"Name": "VMName@2017-11-14 21:02:54",
"Type": "BackupTaskSessionReference"
},
{
"Rel": "Related",
"Href": "https://10.255.147.125:9398/api/vmRestorePoints/6f27c79f-1d5c-4cf9-b5f8-43143447bc00?format=Entity",
"Name": "VMName@2017-11-14 21:03:03",
"Type": "VmRestorePoint"
}
],
"Href": "https://10.255.147.125:9398/api/backupTaskSessions/540c9985-52ab-ab01-a453-e0126edf8716?format=Entity",
"Type": "BackupTaskSession"
}
The objective is to display all elements in root json with jq, like this :
{
"JobSessionUid": "urn:veeam:BackupJobSession:fe8a7b44-5d5d-4767-e5f4-db0dba854c59",
"CreationTimeUTC": "2017-11-14T21:02:54Z",
"EndTimeUTC": "2017-11-14T21:03:30Z",
"State": "Completed",
"Result": "Success",
"Reason": "",
"TotalSize": 599785472,
"VmUid": "urn:VMware:Vm:11e45620-a0dc-1278-6d13-11a58ce70564.vm-1128",
"VmDisplayName": "VMName",
"Name": "VMName@2017-11-14 21:02:54",
"UID": "urn:veeam:BackupTaskSession:540c9985-52ab-ab01-a453-e0126edf8716",
"BackupServerReference": "veeam-dcc-02",
"BackupJobSessionReference": "Backup Name@2017-11-14 21:00:02",
}
I try several commands without success :
jq '{VmDisplayName,CreationTimeUTC,EndTimeUTC,Reason,Result,State,TotalSize} as $root | (.Links[] | select((.Type == "BackupServerReference") or (.Type == "BackupJobSessionReference"))) | . as $ref | $root + $ref'
jq '{VmDisplayName,CreationTimeUTC,EndTimeUTC,Reason,Result,State,TotalSize} as $root | (.Links[] | + {"BackupServerReference": select(.Type == "BackupServerReference")}) | . as $ref | $root + $ref'
Can you help me ?
Best regards,