Hi,
I'm trying to defne a JSON object directly in a script and then output it:
$jsonData = @"
{
"Base": {
"accessGroup": "Root",
"description": null,
"name": "VDI001",
"displayName": "POC"
}
}
"@
$jsonData | ConvertTo-Json | Set-Content VDI001.json
However, what I get back is a messed up file with line breaks and the like:
"{\r\n | \"Base\": {\r\n | \"accessGroup\": \"Root\",\r\n | \"description\": null,\r\n | \"name\": \"VDI001\",\r\n | \"displayName\": \"POC\"\r\n | }\r\n}" |
What am I doing wrong?
-Mark
You are converting a JSON formatted string to JSON.
This should be sufficient to create a JSON file in your example.
$jsonData | Set-Content VDI001.json
The other option is to create a PS object and convert that to JSON
Base = @{
accessGroup = 'Root'
description = $null
name = 'VDI001'
displayName = 'POC'
}
}
$psData | ConvertTo-Json
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are converting a JSON formatted string to JSON.
This should be sufficient to create a JSON file in your example.
$jsonData | Set-Content VDI001.json
The other option is to create a PS object and convert that to JSON
Base = @{
accessGroup = 'Root'
description = $null
name = 'VDI001'
displayName = 'POC'
}
}
$psData | ConvertTo-Json
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference