Preserve datatype name when converting to JSON wit

2020-04-14 07:34发布

问题:

I'm trying to export my SSIS catalog environment to a JSON file (with PowerShell). When I select the right columns I see "String" and "Int16" as value for the Type: but when I convert to JSON with ConvertTo-Json it shows the int values instead of the string values: Any suggestions?

回答1:

Looks like the Type values are of type [System.Data.DbType]. ConvertTo-Json converts the value names to the underlying numerical value of the DbType enum.

You can override this behavior with the Select-Object statement:

$Environment.Variables |Select-Object Name,Description,@{Name='Type';Expression={"$($_.Type)"}},Sensitivity,Value |ConvertTo-Json