0
votes

I have array like below as one of the properties for my object. I'd like to extract certain fields and return it still as array in output. For example I want only name and storageAccountType to be returned like below

Desired Output

[
    {
        "name": "Data",
        "storageAccountType": "Standard_LRS"
    },
    {
        "name": "Disk2",
        "storageAccountType": "Standard_LRS"
    }
]

Input Array

[
    {
        "name": "Data",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Data",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 0
    },
    {
        "name": "Disk2",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Disk2",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 1
    }
]
1

1 Answers

0
votes

here's a direction you could follow (which assumes you actually needs to get back arrays and not to have each element in the array in its own row. if the latter is good, remove the rows with the comments (// *)

datatable(some_value:string, d:dynamic) // just a sample data set with 2 records
[
    "hello", dynamic([
    {
        "name": "Data",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Data",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 0
    },
    {
        "name": "Disk2",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Disk2",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 1
    }
]), "world", dynamic([
    {
        "name": "Data3",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Data",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 0
    },
    {
        "name": "Disk23",
        "createOption": "Attach",
        "diskSizeGB": 10,
        "managedDisk": {
            "id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Disk2",
            "storageAccountType": "Standard_LRS"
        },
        "caching": "None",
        "toBeDetached": false,
        "lun": 1
    }
])
]
// --> answer starts here <--
| extend r = rand() // *
| mv-apply d on (   
    project d = pack("name", d.name, "storageAccountType", d.managedDisk.storageAccountType)
)
| summarize d = make_list(d) by r, some_value // *
| project-away r // *