Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

powershell convert to json

You could try some string manipulation to get it in an expected JSON format, and then use ConvertFrom-Json to convert it to a PSCustomObject.

Simple Example: (simple because this assumes that these characters being replaced will only be delimiters)

# First, clean up the string.
PS C:> $mystring = "@{Account='User01';Domain='Domain01';Admin='True'}"
PS C:> $mystring = $mystring -replace "^@", ""
PS C:> $mystring = $mystring -replace "=", ":"
PS C:> $mystring = $mystring -replace ";", ","
PS C:> $mystring
{Account:'User01',Domain:'Domain01',Admin:'True'}

# Afterwards, convert to PSCustomObject.
PS C:> $myobject = $mystring | ConvertFrom-Json
PS C:> $myobject

Account                                 Domain                                  Admin
-------                                 ------                                  -----
User01                                  Domain01                                True
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #powershell #convert #json
ADD COMMENT
Topic
Name
7+4 =