I would like to convert a human-readable list such as this:
Enabled: No
Server: localhost
Port: 8888
Authenticated Proxy Enabled: 0
... into an object, preferably sanitized as JSON, such as this:
{
"Enabled": "No",
"Server": "localhost",
"Port": 8888,
"Authenticated Proxy Enabled": 0
}
But I expect that implementing this directly would lead to hard-to-track bugs.
I am working on a Node.js app which happens to make use of some built in networking tools on OS X via shelljs. This is where the list comes from and I simply need to process it.
Here is a command you can run from Terminal easily to see roughly what I see:
networksetup -getwebproxy Wi-Fi
Assuming you have a "network service" called Wi-Fi, that should spit out a list like the one above.
I would prefer numbers parsed as numbers, not strings. But I could live without that.
Please note: I am specifically looking to avoid re-inventing the wheel. Doing this myself would be relatively easy, but I want to find a small module for this mundane nuance of processing the data. I am asking to list projects which do this already.
This problem is difficult to search for.
That first snippet could easily be YAML, so get a YAML parser, decode the YAML and encode it into JSON:
JSON.stringify(yaml.safeLoad(fs.readFileSync('example.yml', 'utf8')))