Home > Software engineering >  Parse data from txt file
Parse data from txt file

Time:01-05

I have a text file that I pulled from an OpenvVPN server to get all user data (./sacli userpropget). I'm trying to send all its content, using PowerShell, to a csv file, but I don't know how to parse it, this is an example of the values that I have inside the txt file.

{
  "Development Access": {
    "c2s_dest_s": "false",
    "c2s_dest_v": "false",
    "group_declare": "true",
    "group_range.0": "1.1.1.1-2.2.2.2",
    "group_subnets.0": "1.1.1.0/24",
    "prop_autologin": "false",
    "prop_deny": "false",
    "prop_superuser": "false",
    "type": "group"
  }.

How can I remove the '{}' from it and create columns with the result, like:

c2_dest_s | group_declar  |  

false -----   | true     

CodePudding user response:

As @santiago posted in the comments you need to convert your json to an object, and then you can use it how you like, for example exporting to a csv file

$json = get-content 'C:\temp\test.json'
$obj = $json | ConvertFrom-Json 
$obj.'Development Access' | export-csv C:\temp\test.csv -NoTypeInformation
  • Related