See below both $a
and $s
are strings containing the text "String"
but each serializes differently with ConvertTo-JSON.
Why won't $s | ConvertToJson
produce "String"
??
PS W:\PowerShell\powowshell> $a="String"
PS W:\PowerShell\powowshell> $a
String
PS W:\PowerShell\powowshell> $a.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS W:\PowerShell\powowshell> $a | ConvertTo-Json
"String"
PS W:\PowerShell\powowshell> $s
String
PS W:\PowerShell\powowshell> $s.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS W:\PowerShell\powowshell> $s | ConvertTo-Json
{
"value": "String",
"required": "true"
}
Back-Story
$s
is the parameterValue
of a .ps1
inspected with Get-Help
:
PS W:\PowerShell\powowshell> $cmd = (get-help -full W:\PowerShell\powowshell\examples\components\dosdir.ps1).Syntax.syntaxItem[0].parameter
PS W:\PowerShell\powowshell> $cmd | convertto-json
{
"description": [
{
"Text": "The path to the directory to be listed"
}
],
"parameterValue": {
"value": "String",
"required": "true"
},
...
$s = $cmd.parameterValue
dosdir.ps1:
param(
[String]$Path
)
CMD /C "DIR /B $Path"