Public/ConvertTo-NTFlatJSON.ps1

function ConvertTo-NTFlatJSON
{
    [CmdletBinding()]
    [OutputType([System.String])]
    param
    (
        [Parameter(Mandatory = $true,
                   ValueFromPipeline = $true)]
        [ValidateNotNullOrEmpty()]
        [ValidateScript({
                $Length = $(ConvertTo-Json $_).replace("`r`n", "").Replace(" ", "").Length; if ($length -ge 256) { Throw "Tag value need to be less that 256 characters long, including white spaces etc. Current length $($length)" }
                else { $true }
            })]
        [object]$InputObject
    )
    
    Process
    {
        try
        {
            $(ConvertTo-Json $InputObject).replace("`r`n", "").Replace(" ", "") # Converts JSON to single line
        }
        Catch
        {
            Write-Error "Unable to convert Tag Input to Object from JSON. Error: $($_.Exception.Message)"
        }
    }
}