A
A
arruah2018-10-07 17:34:05
JSON
arruah, 2018-10-07 17:34:05

How to properly parse JSON output using jq?

I'm trying to parse JSON output like this:

{
{
  "data": {
    "1KGChqSML4E4qQRDAegvD35eWzkoNuQ5eT": {
      "address": {
        "type": "pubkeyhash",
        "script_hex": "76a914c8524609cb7235ff6b2d106ce20843747a7062e088ac",
        "balance": 421322,
        "balance_usd": 27.7573674752,
        "received": 842644,
        "received_usd": 55.5148,
        "spent": 421322,
        "spent_usd": 27.7574,
        "output_count": 2,
        "unspent_output_count": 1,
        "first_seen_receiving": "2018-10-07 12:03:22",
        "last_seen_receiving": "2018-10-07 12:03:22",
        "first_seen_spending": "2018-10-07 14:31:36",
        "last_seen_spending": "2018-10-07 14:31:36",
        "transaction_count": 2
      },
      "transactions": [
        "8350f0e1364462e0b6751f744e036246db24e17568235d0f9d75eb8b8b2e373d",
        "a5f6689cff13f7f32ce04bb14b73bd7887704723244439505e87afa20405b12d"
      ]
    }
  },
  "context": {
    "code": 200,
    "source": "D",
    "time": 0.11177706718444824,
    "limit": "100",
    "offset": 0,
    "results": 1,
    "state": 544780,
    "cache": {
      "live": false,
      "duration": 30,
      "since": "2018-10-07 14:31:42",
      "until": "2018-10-07 14:32:12",
      "time": 0.0011708736419677734
    },
    "api": {
      "version": "2.0.4",
      "last_major_update": "2018-07-19 18:07:19",
      "next_major_update": null,
      "tested_features": "omni-v.a1,whc-v.a1",
      "documentation": "https://github.com/Blockchair/Blockchair.Support/blob/master/API.md"
    }
  }
}

I get it with the string
curl -s https://api.blockchair.com/bitcoin/dashboards/address/1KGChqSML4E4qQRDAegvD35eWzkoNuQ5eT | jq

How can I take only the "balance" value from this output?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
egor_nullptr, 2018-10-07
@arruah

curl -s <URL> | jq '..|.balance?|select(. != null)'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question