@arruah

Как правильно спарсить JSON вывод при помощи jq?

Я пытаюсь спарсить JSON вывод типа:
{
{
  "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"
    }
  }
}


Получаю я его при помощи строки
curl -s https://api.blockchair.com/bitcoin/dashboards/address/1KGChqSML4E4qQRDAegvD35eWzkoNuQ5eT | jq

Как мне из этого вывода забрать только значение "balance"?
  • Вопрос задан
  • 94 просмотра
Решения вопроса 1
egor_nullptr
@egor_nullptr
curl -s <URL> | jq '..|.balance?|select(. != null)'
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы