convertfrom-json

Why is PowerShell applying the predicate of a `Where` to an empty list

廉价感情. 提交于 2020-08-19 09:06:27
问题 If I run this in PowerShell, I expect to see the output 0 (zero): Set-StrictMode -Version Latest $x = "[]" | ConvertFrom-Json | Where { $_.name -eq "Baz" } Write-Host $x.Count Instead, I get this error: The property 'name' cannot be found on this object. Verify that the property exists and can be set. At line:1 char:44 + $x = "[]" | ConvertFrom-Json | Where { $_.name -eq "Baz" } + ~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId :

ConvertTo-Json and ConvertFrom-Jason with special characters

℡╲_俬逩灬. 提交于 2019-12-21 14:38:28
问题 I have a file containing some properties which value of some of them contains escape characters, for example some Urls and Regex patterns. When reading the content and converting back to the json, with or without unescaping, the content is not correct. If I convert back to json with unescaping, some regular expression break, if I convert with unescaping, urls and some regular expressions will break. How can I solve the problem? Minimal Complete Verifiable Example Here are some simple code