0

This is the code I have to alter, I have copied the file into terminal and now need to put my own ID etc into the code. I used Cat do see this code but not sure how to edit it. Any help appreiated as I am using this for a demonstration of how sleep stats work on facebook.

{
    "fbCookie": {
        "c_user": "",
        "xs": ""
    },
    "pollingInterval": 600,
    "appId": 435522656639081,
    "server": {
        "port": 3000
    }
}
{
    "fbCookie": {
        "c_user": "",
        "xs": ""
    },
    "pollingInterval": 600,
    "appId": 435522656639081,
    "server": {
        "port": 3000
    }
}
steeldriver
  • 136,215
  • 21
  • 243
  • 336

1 Answers1

0

You can use the jq tool for manipulating JSON from the command line, ex.

$ jq --arg u "myuser" '.fbCookie.c_user |= $u' file.json
{
  "fbCookie": {
    "c_user": "myuser",
    "xs": ""
  },
  "pollingInterval": 600,
  "appId": 435522656639081,
  "server": {
    "port": 3000
  }
}
{
  "fbCookie": {
    "c_user": "myuser",
    "xs": ""
  },
  "pollingInterval": 600,
  "appId": 435522656639081,
  "server": {
    "port": 3000
  }
}

or

$ jq --argjson c '{"c_user": "myuser", "xs": "foo bar"}' '.fbCookie |= $c' file.json
{
  "fbCookie": {
    "c_user": "myuser",
    "xs": "foo bar"
  },
  "pollingInterval": 600,
  "appId": 435522656639081,
  "server": {
    "port": 3000
  }
}
{
  "fbCookie": {
    "c_user": "myuser",
    "xs": "foo bar"
  },
  "pollingInterval": 600,
  "appId": 435522656639081,
  "server": {
    "port": 3000
  }
}
steeldriver
  • 136,215
  • 21
  • 243
  • 336