Skip to content

Instantly share code, notes, and snippets.

@lavabyrd
Last active January 12, 2022 22:11
Show Gist options
  • Save lavabyrd/40319e1531701d04cbe57ce255d21ad8 to your computer and use it in GitHub Desktop.
Save lavabyrd/40319e1531701d04cbe57ce255d21ad8 to your computer and use it in GitHub Desktop.
JQ Example

curl https://cosmoshub-4--rpc--full.datahub.figment.io/apikey/{api_key}/status

result:

{
  "jsonrpc": "2.0",
  "id": -1,
  "result": {
    "node_info": {
      "protocol_version": {
        "p2p": "8",
        "block": "11",
        "app": "0"
      },
      "id": "a9236456796cd2c04baa89ad09a585b76b0cb1e5",
      "listen_addr": "tcp://66.70.178.45:26656",
      "network": "cosmoshub-4",
      "version": "v0.34.14",
      "channels": "40202122233038606100",
      "moniker": "3movIIhQhS",
      "other": {
        "tx_index": "on",
        "rpc_address": "tcp://0.0.0.0:26657"
      }
    },
    "sync_info": {
      "latest_block_hash": "03C4C8A6390D353E1B2741D4A435DD5A2DBEA7C6E394CAC621ECF837A9F3D5EE",
      "latest_app_hash": "24BBC46A2DDC37E629A1A6A86AF5BDCB71834C1C242E4CFE217156DD19B9A1B9",
      "latest_block_height": "9044938",
      "latest_block_time": "2022-01-12T21:37:20.702130558Z",
      "earliest_block_hash": "1455A0C15AC49BB506992EC85A3CD4D32367E53A087689815E01A524231C3ADF",
      "earliest_app_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
      "earliest_block_height": "5200791",
      "earliest_block_time": "2019-12-11T16:11:34Z",
      "catching_up": false
    },
    "validator_info": {
      "address": "5D1567E38B79C037BB366FE698480A8361FAC98A",
      "pub_key": {
        "type": "tendermint/PubKeyEd25519",
        "value": "cpsv5N6sDCXYJ0wPnV87emf7FDW3+7ibR+5CMKecyqE="
      },
      "voting_power": "0"
    }
  }
}

If I was to pipe the output to a jq argument, I could do something like this:

curl https://... | jq "{height: .result.node_info.protocol_version.block, hash: .result.sync_info.latest_block_hash}"

{
  "height": "11",
  "hash": "0FECBF2825EECA89BEF5791FB2A12C72196DCD379D3D968ED44CD6B45BFD715B"
}

Using this, I can target particular fields with any labels I want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment