I am using below code to regenerate my Json using PowerShell, however it creates unexpected character before the start of the json { tag.
<#$data = Get-Content -Raw -Path myfile.json | ConvertFrom-Json#>
$data = @"
{
"stations": [
{
"code": "1",
"name": "United force"
},
{
"code": "2",
"name": "Toowoon Bay Service Station"
}
],
"prices": [
{
"stationcode": "1",
"fueltype": "DL",
"price": 126.97
},
{
"stationcode": "1",
"fueltype": "E10",
"price": 118.92
},
{
"stationcode": "2",
"fueltype": "E10",
"price": 112.90
},
{
"stationcode": "2",
"fueltype": "P95",
"price": 125.90
},
{
"stationcode": "2",
"fueltype": "P98",
"price": 155.90
},
{
"stationcode": "2",
"fueltype": "U91",
"price": 115.20
}
]
}
"@ | ConvertFrom-Json
foreach ($price in $data.prices) {
$data.stations |
Where-Object { $_.code -eq $price.stationcode } |
Add-Member -MemberType NoteProperty -Name $price.fueltype -Value $price.price
}
$data | Select-Object -Property stations | ConvertTo-Json | Set-Content "testJson.json" -Encoding UTF8
When calling this file after uploading, I am having trouble reading the json file due to that unexpected character.
Hope someone can help in the PowerShell code to ensure there is no character like that, I may be doing something easy but not sure how.
I am reading the generated json file after the PowerShell to Flutter, which throws the error as shown below

Thanks,
