Skip to content

nightmare dealing with escaped Unicode sequences #2

@stratanic

Description

@stratanic

Hello,
your addon powershell is great...

he take me many day to discover this nightmare dealing with escaped Unicode sequences.

can you have tips ?

I try this after micrsoft copilot help me:
= [System.Text.RegularExpressions.Regex]::Unescape($jqoutputcontent)

full code to correct your class powershell (by copilot)

class MyJsonClass
{
    [object] $MyJsonData = $null

    MyJsonClass([string]$JsonFilePath)
    {
        # Lire le contenu du fichier JSON avec encodage UTF-8
        $jsonContent = Get-Content -Path $JsonFilePath -Raw -Encoding UTF8
        $this.MyJsonData = $jsonContent | ConvertFrom-Json
    }

    [string] GetJsonValue()
    {
        $jsonString = $this.MyJsonData | ConvertTo-Json -Depth 99
        $decodedJsonString = [MyJsonClass]::DecodeUnicodeString($jsonString)
        return $decodedJsonString
    }

    [string] static DecodeUnicodeString([string]$input)
    {
        return [System.Text.RegularExpressions.Regex]::Unescape($input)
    }
}

# Utilisation de la classe
$instance = [MyJsonClass]::new("...\Prtg_to_alerta\rawjson-fileRAW.json")
Write-Output $instance.GetJsonValue()

sample api (PRTG monitoring)
image

I join sample file json: utf8
rawjson-file.json

thanks for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions