Wednesday, 18 May 2022

Unable to parse JSON? Or is it JavaScript text (EDIT: How to parse a custom config file)

I am trying to parse what I originally suspected was a JSON config file from a server.

After some attempts I was able to navigate and collapse the sections within Notepad++ when I selected the formatter as JavaScript.

However I am stuck on how I can convert/parse this data to JSON/another format, no online tools have been able to help with this.

How can I parse this text? Ideally I was trying to use PowerShell, but Python would also be an option if I can figure out how I can even begin the conversion.

Thank you!

For example, I am trying to parse out each of the servers, ie. test1, test2, test3 and get the data listed within each block.

Here is a sample of the config file format:

servername {
  store {
    servers {
      * {
        value<>
        port<>
        folder<C:\windows>
        monitor<yes>
        args<-T -H>
        xrg<store>
        wysargs<-t -g -b>
        accept_any<yes>
        pdu_length<23622>
      }
      test1 {
        name<test1>
        port<123>
        root<c:\test>
        monitor<yes>
      }
      test2 {
        name<test2>
        port<124>
        root<c:\test>
        monitor<yes>
      }
      test3 {
        name<test3>
        port<125>
        root<c:\test>
        monitor<yes>
      }
    }
    senders
    timeout<30>
  }
}

EDIT: Adding bounty after the fact for @zett42 for his amazing work and effort in producing a solution to my problem!



from Unable to parse JSON? Or is it JavaScript text (EDIT: How to parse a custom config file)

No comments:

Post a Comment