Skip to content

Tips for developing

Yoshihide Jimbo edited this page Nov 23, 2013 · 1 revision

Combining cURL and jq is so useful to develop and confirm API responses.

jq

jq is a lightweight and flexible command-line JSON processor. It is available for Linux, OS X and Windows.

Only curl command

$ curl -s 'http://taxman.openspending.org/gb?income=22000'
{"options":{"year":2013,"income":22000,"age":null,"indirects":null,"blind":null,"documentation":null},"data":{"allowances":{"personal":9440,"personal_income_limit":100000,"blind":2160,"born_before_apr_1938":1220,"born_apr_1938_to_apr_1948":1060,"aged_income_limit":26100},"income_tax":{"bands":[{"width":32010,"rate":0.2},{"width":117989,"rate":0.4},{"rate":0.45}]},"national_insurance":{"pt":7748,"uel":41444,"mcr":0.12,"acr":0.02}},"calculation":{"total":4222,"allowances":{"personal":9440,"blind":0,"age_related":0,"total":9440},"taxable":12560,"income_tax":{"total":2512,"bands":[2512,0,0]},"national_insurance":{"total":1710,"bands":[1710,0]},"directs":{"total":4222}}}

Piping through jq

$ curl -s 'http://taxman.openspending.org/gb?income=22000' | jq '.'
{
  "calculation": {
    "directs": {
      "total": 4222
    },
    "national_insurance": {
      "bands": [
        1710,
        0
      ],
      "total": 1710
    },
    "income_tax": {
      "bands": [
        2512,
        0,
        0
      ],
      "total": 2512
    },
    "taxable": 12560,
    "allowances": {
      "total": 9440,
      "age_related": 0,
      "blind": 0,
      "personal": 9440
    },
    "total": 4222
  },
  "data": {
    "national_insurance": {
      "acr": 0.02,
      "mcr": 0.12,
      "uel": 41444,
      "pt": 7748
    },
    "income_tax": {
      "bands": [
        {
          "rate": 0.2,
          "width": 32010
        },
        {
          "rate": 0.4,
          "width": 117989
        },
        {
          "rate": 0.45
        }
      ]
    },
    "allowances": {
      "aged_income_limit": 26100,
      "born_apr_1938_to_apr_1948": 1060,
      "born_before_apr_1938": 1220,
      "blind": 2160,
      "personal_income_limit": 100000,
      "personal": 9440
    }
  },
  "options": {
    "documentation": null,
    "blind": null,
    "indirects": null,
    "age": null,
    "income": 22000,
    "year": 2013
  }
}

Getting only options object

$ curl -s 'http://taxman.openspending.org/gb?income=22000' | jq '.options'
{
  "documentation": null,
  "blind": null,
  "indirects": null,
  "age": null,
  "income": 22000,
  "year": 2013
}

Visit the offical website for more.

Clone this wiki locally