代码语言:powershell 复制 # 创建一个包含子数组的哈希表 $hashTable = @{ "name" = "John"; "age" = 30; "languages" = @("English", "Spanish", "French"); } # 将哈希表转换为JSON字符串 $json = $hashTable | ConvertTo-Json # 输出JSON字符串
如果不使用开关,将 JSON 转换为 PSObject 然后用 ConvertTo-Json 命令转换回来会产生一个单一的整数。 参数 -AsHashtable 将JSON 转换为哈希表对象。 PowerShell 6.0 中引入了此开关。 从 PowerShell 7.3 开始,对象是 OrderHashtable,并保留 JSON 中的键排序。 在早期版本中,对象是 哈希表。 有几个方案可以...
[hashtable]$data, [string]$sensitiveKey ) if ($data.ContainsKey($sensitiveKey)) { $data[$sensitiveKey] = "***" } return $data } # 使用函数掩码密码字段 $maskedData = Mask-SensitiveData -data $jsonContent -sensitiveKey "password" # 输出掩码后的数据 $maskedData | ConvertTo-Json 遇到...
If you expand the "Derived" link in that article, you can see that PowerShell's [hashtable] (full type name is[System.Collections.Hashtable]) and [ordered] (full type name is[System.Collections.Specialized.OrderedDictionary]) are both in that list, meaning they are compatible with the ...
$text | ConvertTo-Json The cmdlet properly escapes the quotes and backslashes in the output JSON. This ensures the JSON remains valid and can be parsed correctly. Custom object conversion You can convert custom PowerShell objects to JSON. This works with both hashtables and PSObjects. The con...
PowerShell v3 brings the possibility to create a custom object via [pscustomobject] 1$CustomObject2= [pscustomobject]@{a=1; b=2; c=3; d=4} 2 3$CustomObject2|Format-List Note: both methods create a PSCustomObject with NoteProperties, not a hashtable object ...
Package: Microsoft.PowerShell.Commands.Utility v7.4.0 JsonObject class. C++ コピー public ref class JsonObject abstract sealed Inheritance Object JsonObject Methods テーブルを展開する ConvertFromJson(String, Boolean, ErrorRecord) Convert a Json string back to an object of type PSObject ...
Module: Microsoft.PowerShell.Utility Converts a JSON-formatted string to a custom object or a hash table.SyntaxPowerShell Kopiraj ConvertFrom-Json [-InputObject] <String> [-AsHashtable] [-Depth <Int32>] [-NoEnumerate] [<CommonParameters>]...
Package: Microsoft.PowerShell.Commands.Utility v7.4.0 JsonObject class. C++ 複製 public ref class JsonObject abstract sealed Inheritance Object JsonObject Methods 展開資料表 ConvertFromJson(String, Boolean, ErrorRecord) Convert a Json string back to an object of type PSObject or Hashtable ...
Módulo: Microsoft.PowerShell.Utility Convierte una cadena con formato JSON en un objeto personalizado o en una tabla hash.SyntaxPowerShell Kopiatu ConvertFrom-Json [-InputObject] <String> [-AsHashtable] [-Depth <Int32>] [-NoEnumerate] [<CommonParameters>]...