Completely stuck with this one.
I've got JSON Like this:
{
"create_option": "Restore",
"disk_iops_read_write": 120,
"disk_mbps_read_write": 25,
"tags": {
"Monitor": "No",
"RSVaultBackup": "2dc504bd"
}
}
and with the following jq
.|to_entries|map("nfs-0_\(.key)=\"\(.value)\"")|.[]
I've got to this
nfs-0_create_option="Restore"
nfs-0_disk_iops_read_write="120"
nfs-0_disk_mbps_read_write="25"
nfs-0_tags="{"Monitor":"No","RSVaultBackup":"2dc504bd"}"
but the nfs-0_tags line section also needs to be in name=value format. What I want to end up with is this
nfs-0_create_option="Restore"
nfs-0_disk_iops_read_write="120"
nfs-0_disk_mbps_read_write="25"
nfs-0_tags={Monitor="No", VaultBackup="2dc504bd"}
I feel I should be able to recursively apply the map but for the life of me I can't figure out how that might be achieved.
Any ideas?
Thanks :)
EDIT:
Okay I think I'm getting a bit closer now with this
.|.tags |= (to_entries | map("\(.key) = \(.value)"))|to_entries|map ("\(.key) = \(.value)")|.[]
I'm now getting
create_option = Restore
disk_iops_read_write = 120
disk_mbps_read_write = 25
tags = ["Monitor = No","RSVaultBackup = 2dc504bd"]
But I need the tags line in curly braces {} with the key unquoted and the value quoted. Like this
nfs-0_tags={Monitor="No", VaultBackup="2dc504bd"}
EDIT:
I still want the output to look like this
nfs-0_create_option="Restore"
nfs-0_disk_iops_read_write="120"
nfs-0_disk_mbps_read_write="25"
nfs-0_tags={Monitor="No", VaultBackup="2dc504bd"}
after the jq runs