Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

how to convert back to JSON in powershell

ConvertTo-Json -InputObject $my_object
Comment

PREVIOUS NEXT
Code Example
Shell :: wsl start distro 
Shell :: git push local branch to remote repo 
Shell :: uncommit local commit 
Shell :: zfs check compression type 
Shell :: delete remote commit 
Shell :: add key file to ssh 
Shell :: ubuntu install latest vim 
Shell :: powershell clear command 
Shell :: drupal cli composer 
Shell :: expo install package version 
Shell :: open folder from terminal ubuntu 
Shell :: gitignore file download 
Shell :: netcat reverse shell 
Shell :: download images from url terminal 
Shell :: django start project in existing directory 
Shell :: composer installation cmd 
Shell :: how to start a background process in ubuntu 
Shell :: uninstall package with yarn 
Shell :: ssh 
Shell :: install docker debian 
Shell :: umask 
Shell :: git clone with long file names 
Shell :: vim cut paste 
Shell :: commit and push 
Shell :: opera libffmpeg.so 
Shell :: Copy a Remote File to a Local System using the scp Command 
Shell :: libssl-dev ubuntu get version 
Shell :: branch conflicts 
Shell :: linux history delete line 
Shell :: awk uppercase first character 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =