I have a json object which returns from the following PowerShell command:
Get-Service -Name "name" | ConvertTo-Json -Compress > "/to/path/name.json"
If i basically open the file in vscode it seems to be correctly formatted. After i read the file with
 fs.readFile(file, 'utf8', (err, data)...
and then try JSON.parse(data) im receiving the error:
undefined:1
��{
^
SyntaxError: Unexpected token � in JSON at position 0
Then i tried to do the following:
data.replace(/[^\x00-\x7F]/g, "") to only have ASCII characters, which basically seems to work at least with a console.log().
But JSON.parse then complains:
undefined:1
{
 
SyntaxError: Unexpected token  in JSON at position 1
Im not sure whats the problem there. Hopefully somebody can help me with that.
This is an example json file: As i think the format is correct. Only too much spaces which are removed by the -Compress PowerShell parameter.
{
    "CanPauseAndContinue":  false,
    "CanShutdown":  false,
    "CanStop":  false,
    "DisplayName":  "OpenSSH Authentication Agent",
    "DependentServices":  [
                          ],
    "MachineName":  ".",
    "ServiceName":  "ssh-agent",
    "ServicesDependedOn":  [
                           ],
    "ServiceHandle":  {
                          "IsInvalid":  false,
                          "IsClosed":  false
                      },
    "Status":  1,
    "ServiceType":  16,
    "StartType":  4,
    "Site":  null,
    "Container":  null,
    "Name":  "ssh-agent",
    "RequiredServices":  [
                         ]
}
 
     
     
     
     
    