Apr 9, 2019

Stripping Parsing JSON with nodejs

You want to have a json file with comments for your config file. How do you parse it?

kamathln@laxX550L:~/exp/nodejs $ cat json.json
{
"really":"simple",
/* commanted out code */
"test":["hmm", "this", {Just: "worked"}]
}


kamathln@laxX550L:~/exp/nodejs $ node -p "res = $(cat json.json); JSON.stringify(res, null, 4)"
{
    "really": "simple",
    "test": [
        "hmm",
        "this",
        {
            "Just": "worked"
        }
    ]
}