I am creating an arm template to deploy data sets in ADF, for that i need to update an existing json file with new key value pairs based on my input file. how do i add new key v
You don't need Add-Member
, you simply need to "append" to the existing array in .properties.structure
(technically, you're creating a new array that includes the new elements).
Here's a simplified example:
# Sample JSON.
$json = @'
{
"name": "[concat(parameters('factoryName'), '/Veh_Obj')]",
"properties": {
"type": "AzureDataLakeStoreFile",
"structure": [
{
"name": "VIN",
"type": "String"
},
{
"name": "MAKE",
"type": "String"
}
],
}
}
'@
# Convert from JSON to a nested custom object.
$obj = $json | ConvertFrom-Json
# Append new objects to the array.
$obj.properties.structure += [pscustomobject] @{ name = 'newname1' },
[pscustomobject] @{ name = 'newname2' }
# Convert back to JSON.
$obj | ConvertTo-Json -Depth 3
The above yields:
{
"name": "[concat(parameters('factoryName'), '/Veh_Obj')]",
"properties": {
"type": "AzureDataLakeStoreFile",
"structure": [
{
"name": "VIN",
"type": "String"
},
{
"name": "MAKE",
"type": "String"
},
{
"name": "newname1"
},
{
"name": "newname2"
}
]
}
}