I have the following Function that creates a JSON:
Function New-JSONTest {
Param (
[Parameter( ParameterSetName = "NewConfig" )]
[switch]$NewConfig
)
$PSCustomObject = switch ($PSCmdLet.ParameterSetName) {
NewConfig {
[PSCustomObject]@{
Menus = @(
[PSCustomObject]@{
Name = "Produktauswahl"
IsEnabledByDefault = $true
IsVisibleByDefault = $true
IsEnabledIf = ""
IsVisibleIf = ""
OnClickAction = [PSCustomObject]@{
ActionCode = 3
Parameter = @(
[PSCustomObject]@{
ParameterName = "TestInput.Menü"
ParameterType = "string"
ParameterValue = "Menus.Name"
}
)
}
},
[PSCustomObject]@{
Name = "Grundkonfiguration"
IsEnabledByDefault = $false
IsVisibleByDefault = $true
IsEnabledIf = ""
IsVisibleIf = ""
OnClickAction = [PSCustomObject]@{
ActionCode = 3
Parameter = @(
[PSCustomObject]@{
ParameterName = "TestInput.Menü"
ParameterType = "string"
ParameterValue = "Menus.Name"
}
)
}
},
[PSCustomObject]@{
Name = "Zubehörkonfiguration"
IsEnabledByDefault = $false
IsVisibleByDefault = $true
IsEnabledIf = ""
IsVisibleIf = ""
OnClickAction = [PSCustomObject]@{
ActionCode = 3
Parameter = @(
[PSCustomObject]@{
ParameterName = "TestInput.Menü"
ParameterType = "string"
ParameterValue = "Menus.Name"
}
)
}
},
[PSCustomObject]@{
Name = "Konfiguration abschliessen"
IsEnabledByDefault = $false
IsVisibleByDefault = $true
IsEnabledIf = ""
IsVisibleIf = ""
OnClickAction = [PSCustomObject]@{
ActionCode = 3
Parameter = @(
[PSCustomObject]@{
ParameterName = "TestInput.Menü"
ParameterType = "string"
ParameterValue = "Menus.Name"
}
)
}
}
)
}
}
}
# Return as JSON
$PSCustomObject | ConvertTo-Json
}
As you can see, in each Menus
Object, I have a OnClickAction
Object with another nested PSCustomObject
in an array.
When I run the code, each Menu
I get returned looks like this:
{
"Name": "Produktauswahl",
"IsEnabledByDefault": true,
"IsVisibleByDefault": true,
"IsEnabledIf": "",
"IsVisibleIf": "",
"OnClickAction": "@{ActionCode=3; Parameter=System.Object[]}"
}
Can I somehow force it to Display my OnClickAction
also in an expanded JSON, instead of an array that is not readable? Basically what I need in the End is this:
{
"Menus": [
{
"Name": "Produktauswahl",
"IsEnabledByDefault": true,
"IsVisibleByDefault": true,
"IsEnabledIf": "",
"IsVisibleIf": "",
"OnClickAction": {
"ActionCode": "3",
"Parameter": [
"ParameterName": "TestInput.Menü"
"ParameterType": "string"
"ParameterValue": "Menus.Name"
]
}
}
]
}
Is this possible or am I misunderstanding something?