I want to displaying data from json to env file with this output
OnSubscription=True; Name=John; Surname=Smith
but when I create data, its showing like this
@{OnSubscription=True; Name=John; Surname=Smith}
and this is my script
$Path2 = ".\output\env"
$x = Get-Content .\basket.json| ConvertFrom-Json
foreach( $rootProperty in @($x.psobject.properties | where-object {$_.MemberType -eq "NoteProperty"}) )
{
write-host "'$($rootProperty.Name)' = '$($rootProperty.Value)'"
foreach( $childProperty in @($rootProperty.Value.psobject.properties | where-object {$_.MemberType -eq "NoteProperty"}) )
{
write-host "'$($childProperty.Name)' = '$($childProperty.Value)'"
}
$result = Add-Content -Path $Path2 "$($rootProperty.Value) "
$result = Add-Content -Path $Path2 "$($childProperty.Value) "
}
This is my sample of json
{
"Customer": {
"OnSubscription": true,
"Name": "John",
"Surname": "Smith"
},
"Data": {
"Basket": [
"apples",
"pears",
"oranges",
"strawberries"
]
}
}
How to remove this @{} ? I already follow this example Create .env file from a .json file but with power shell