Home > Blockchain >  Extract multiple nested in a single JQ run
Extract multiple nested in a single JQ run

Time:10-03

I need to extract multiple nested fields from a json payload. Here is an example of a payload.

{
  "data": [
    {
      "version": 10030002,
      "type": "poc_request_v1",
      "time": 1632442480,
      "secret_hash": "5AGdvx6te0KwMfHaTjsLHlTBcW5N14d1mBooiBKvW-Y",
      "onion_key_hash": "ONR5Z8TmpnJo73Xr2H_4P18IAH5dUwvRKDFhcO_iAJ8",
      "height": 1023815,
      "hash": "kezroutI0xpWe8glndloExmbww2U-EMI0Xb3sZa_ma4",
      "fee": 0,
      "challenger_owner": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt",
      "challenger_location": "8c2aaa8268753ff",
      "challenger": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
      "block_hash": "M-N28KOlVvIpYaKteJ4pFvPk0XDCmXgSp9V8mUi50lw"
    },
    {
      "type": "rewards_v2",
      "time": 1632441462,
      "start_epoch": 1023764,
      "rewards": [
        {
          "type": "poc_challengees",
          "gateway": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
          "amount": 8000901,
          "account": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt"
        }
      ],
      "height": 1023796,
      "hash": "O2j3mHBdIVLXz0yMWMNAzf3xRJ6J8dxw8AB3DqSNSH0",
      "end_epoch": 1023795
    },
    {
      "type": "poc_receipts_v1",
      "time": 1632440612,
      "secret": "AAtGKfGBp21LZqq2MzcZqCYn1UFVD5ERSytLv4OGY9xWBMUDJHA04jABt-SgcyRUYHkCtO323Bgt5RMxsBbL7HESEY3gldxQGBedYm9wAS5BzvFiW21HjYUp-2-grpH4OwY",
      "request_block_hash": "fhqUiJg-coBBpFa7VqTypWB3-sfHIwnMApdfZ3oD_Aw",
      "path": [
        {
          "witnesses": [
            {
              "timestamp": 1632439246365596700,
              "snr": -5.800000190734863,
              "signal": -113,
              "packet_hash": "gvzk31QfjcDkJw7CU79X55ZXk04Un2Z4PuZOtIhwPnY",
              "owner": "14iwCHcr1KPfNRXPky4RaMhBVoLfHojDMt2Dje2p2XrU3YhAG6j",
              "location_hex": "882aaa80d7fffff",
              "location": "8c2aaa80d6ce7ff",
              "is_valid": true,
              "gateway": "117Hdm1RkxkH9tS632ki8uBzU8w9LyonYKYCXRgiePN5HA59wSq",
              "frequency": 904.0999755859375,
              "datarate": "SF9BW125",
              "channel": 1
            },
            {
              "timestamp": 1632439246401554200,
              "snr": -10.199999809265137,
              "signal": -113,
              "packet_hash": "gvzk31QfjcDkJw7CU79X55ZXk04Un2Z4PuZOtIhwPnY",
              "owner": "14DJ5htcGMHgDB18Dpd5uSsSggLBqir52gvXawBw4mifEiNuaxq",
              "location_hex": "882aaa968bfffff",
              "location": "8c2aaa968b987ff",
              "is_valid": true,
              "gateway": "11BMbZgVNhZwbn3pq4Xggp48eG2W5rVEn9eV9QCZP8hae98Kjb7",
              "frequency": 904.0999755859375,
              "datarate": "SF9BW125",
              "channel": 1
            },
            {
              "timestamp": 1632439244526317300,
              "snr": -2.799999952316284,
              "signal": -117,
              "packet_hash": "gvzk31QfjcDkJw7CU79X55ZXk04Un2Z4PuZOtIhwPnY",
              "owner": "13vv6uqoDQTGkUqo5Wy7APqBuNP1WY2gVBAJx5v15VVwjgyALvW",
              "location_hex": "882aaa8705fffff",
              "location": "8c2aaa87056a1ff",
              "is_valid": true,
              "gateway": "11g73hc6NmPv3dssGN5zgkJGfuhBmCRqxqDjcM16RwEPjWZozg4",
              "frequency": 904.0999755859375,
              "datarate": "SF9BW125",
              "channel": 1
            },
            {
              "timestamp": 1632439244583344600,
              "snr": -14,
              "signal": -115,
              "packet_hash": "gvzk31QfjcDkJw7CU79X55ZXk04Un2Z4PuZOtIhwPnY",
              "owner": "14d2dqrkxVNAYeyxg71HzsQ2ExdbYQJWfq7GoRbv7Y2PregRg4R",
              "location_hex": "882aaa80bdfffff",
              "location": "8c2aaa80bc869ff",
              "is_valid": true,
              "gateway": "11r4BXSjp7nKrxqjiHzS4k4yQkoPBZ2boL4gYA4nhUJbKLvYb1U",
              "frequency": 904.0999755859375,
              "datarate": "SF9BW125",
              "channel": 1
            },
            {
              "timestamp": 1632439246349839000,
              "snr": -15.199999809265137,
              "signal": -112,
              "packet_hash": "gvzk31QfjcDkJw7CU79X55ZXk04Un2Z4PuZOtIhwPnY",
              "owner": "142ooh6JRW8spP7PfRVagqEndSuN3pGcGdZWo5dkPoRRn6EAXTx",
              "location_hex": "882aaa84dbfffff",
              "location": "8c2aaa84da545ff",
              "is_valid": true,
              "gateway": "112iqY2yF2EbKQgxN9nWu2BczqU8qoAYpfrSkUaaea7XEFUWLXgz",
              "frequency": 904.0999755859375,
              "datarate": "SF9BW125",
              "channel": 1
            },
            {
              "timestamp": 1632439246361085700,
              "snr": -12.800000190734863,
              "signal": -119,
              "packet_hash": "gvzk31QfjcDkJw7CU79X55ZXk04Un2Z4PuZOtIhwPnY",
              "owner": "13iC2Fz8Xtw9bD53WYERxTPSUfrQ7d2qdUGdvyH5ocT6jF4bcZ2",
              "location_hex": "882aae28cbfffff",
              "location": "8c2aae28ca583ff",
              "is_valid": true,
              "gateway": "11221nH7EB9U9yBvKQRjXwhC6QUHkKQqLFrosxuTwHkXLjJEP46W",
              "frequency": 904.0999755859375,
              "datarate": "SF9BW125",
              "channel": 1
            },
            {
              "timestamp": 1632439246360691000,
              "snr": -6,
              "signal": -103,
              "packet_hash": "gvzk31QfjcDkJw7CU79X55ZXk04Un2Z4PuZOtIhwPnY",
              "owner": "13DHKGg9VxMLhgcUvnWmLHcfLUpX46ZYMUFU7Hvy8aQDr8eeJMx",
              "location_hex": "882aaa168dfffff",
              "location": "8c2aaa168da27ff",
              "is_valid": true,
              "gateway": "11RaAJUXLEziygkwxBgNcEPPYs2dmYGeZiAr8Ho629UByr5u6nr",
              "frequency": 904.0999755859375,
              "datarate": "SF9BW125",
              "channel": 1
            },
            {
              "timestamp": 1632439246561084700,
              "snr": -4.199999809265137,
              "signal": -112,
              "packet_hash": "gvzk31QfjcDkJw7CU79X55ZXk04Un2Z4PuZOtIhwPnY",
              "owner": "13FmorVZh5uB3QXqUTtfSLDZsoGyNtH766DuZCtcSTS1d9myW2s",
              "location_hex": "882aae75ebfffff",
              "location": "8c2aae75eb2bbff",
              "is_valid": true,
              "gateway": "1128xQoqhYwZbgmXYQCgXQfcihHMWvsuE77dnRvkmUthH7EJXW25",
              "frequency": 904.0999755859375,
              "datarate": "SF9BW125",
              "channel": 1
            },
            {
              "timestamp": 1632439246364830500,
              "snr": -2.200000047683716,
              "signal": -114,
              "packet_hash": "gvzk31QfjcDkJw7CU79X55ZXk04Un2Z4PuZOtIhwPnY",
              "owner": "13VVqYrm4YeBFFu8rwBa3kwgGYkcsuvcLm6fGVhfSVvW2o8udqU",
              "location_hex": "882aaa8421fffff",
              "location": "8c2aaa8421667ff",
              "is_valid": true,
              "gateway": "112L9qP6GRXEhmiH7qkKj6sphUMeXNMxaKuEoMycXco5vbmidme9",
              "frequency": 904.0999755859375,
              "datarate": "SF9BW125",
              "channel": 1
            }
          ],
          "receipt": {
            "tx_power": 0,
            "timestamp": 1632439244895009000,
            "snr": 0,
            "signal": 0,
            "origin": "p2p",
            "gateway": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
            "frequency": 0,
            "datarate": null,
            "data": "aQw",
            "channel": 0
          },
          "geocode": {
            "short_street": "Stumptown Rd",
            "short_state": "VA",
            "short_country": "US",
            "short_city": "Leesburg",
            "long_street": "Stumptown Road",
            "long_state": "Virginia",
            "long_country": "United States",
            "long_city": "Leesburg",
            "city_id": "bGVlc2J1cmd2aXJnaW5pYXVuaXRlZCBzdGF0ZXM"
          },
          "challengee_owner": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt",
          "challengee_lon": -77.53639565293369,
          "challengee_location_hex": "882aaa8269fffff",
          "challengee_location": "8c2aaa8268753ff",
          "challengee_lat": 39.21665905449698,
          "challengee": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK"
        }
      ],
      "onion_key_hash": "wIZSJP7orTBJrv_LzVAetD2yz7CoM-rF5tVseYFqMsc",
      "height": 1023779,
      "hash": "jkK8IIhZI8FQszUrGhQj6CS5Mo_ubTi7FgF1wHeVydU",
      "fee": 0,
      "challenger_owner": "14aL3TLnykg9spujEygbp7L1ZNCS69SqHhpF8EtYyxTny7XUF3h",
      "challenger_lon": -157.99353068344223,
      "challenger_location": "8c46482f0229dff",
      "challenger_lat": 21.48119606796577,
      "challenger": "112ZXALFHvujHsGByny1yxHKfXSJ2CQL5jTEQpfCaVfZ9y2JmKJq"
    },
    {
      "type": "rewards_v2",
      "time": 1632427105,
      "start_epoch": 1023533,
      "rewards": [
        {
          "type": "poc_challengees",
          "gateway": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
          "amount": 6703336,
          "account": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt"
        }
      ],
      "height": 1023565,
      "hash": "ozllRv-RI6j5eC6ICeTH4FfQGJA9eWms5x4U_c7xnE8",
      "end_epoch": 1023564
    },
    {
      "type": "poc_receipts_v1",
      "time": 1632426945,
      "secret": "AO8bck7WawEwM9azahZjkn2PjJyIAc6gEyxNo52Cm7zLBPx_guCGy0vtqS1tQJAd9qhGHmMn11nfpk0AlvyvvtUXGg7aOVTvJxCBS-dhgod5DtQ0t8ZK_Ghvmi0KrEi8jyw",
      "request_block_hash": "XEQR7zaljcwj4SHBZqZo7zRli05g6Q07izZjgm8n5m4",
      "path": [
        {
          "witnesses": [
            {
              "timestamp": 1632426010146206200,
              "snr": -6,
              "signal": -119,
              "packet_hash": "qOK8ETrxcSWBdyLKNBjkYopBeX8b7piwxMFhFRTCfM8",
              "owner": "13vv6uqoDQTGkUqo5Wy7APqBuNP1WY2gVBAJx5v15VVwjgyALvW",
              "location_hex": "882aaa8705fffff",
              "location": "8c2aaa87056a1ff",
              "is_valid": true,
              "gateway": "11g73hc6NmPv3dssGN5zgkJGfuhBmCRqxqDjcM16RwEPjWZozg4",
              "frequency": 904.2999877929688,
              "datarate": "SF9BW125",
              "channel": 2
            },
            {
              "timestamp": 1632426011662074000,
              "snr": -9.5,
              "signal": -113,
              "packet_hash": "qOK8ETrxcSWBdyLKNBjkYopBeX8b7piwxMFhFRTCfM8",
              "owner": "14DJ5htcGMHgDB18Dpd5uSsSggLBqir52gvXawBw4mifEiNuaxq",
              "location_hex": "882aaa968bfffff",
              "location": "8c2aaa968b987ff",
              "is_valid": true,
              "gateway": "11BMbZgVNhZwbn3pq4Xggp48eG2W5rVEn9eV9QCZP8hae98Kjb7",
              "frequency": 904.2999877929688,
              "datarate": "SF9BW125",
              "channel": 2
            },
            {
              "timestamp": 1632426011668748300,
              "snr": -7,
              "signal": -103,
              "packet_hash": "qOK8ETrxcSWBdyLKNBjkYopBeX8b7piwxMFhFRTCfM8",
              "owner": "13DHKGg9VxMLhgcUvnWmLHcfLUpX46ZYMUFU7Hvy8aQDr8eeJMx",
              "location_hex": "882aaa168dfffff",
              "location": "8c2aaa168da27ff",
              "is_valid": true,
              "gateway": "11RaAJUXLEziygkwxBgNcEPPYs2dmYGeZiAr8Ho629UByr5u6nr",
              "frequency": 904.2999877929688,
              "datarate": "SF9BW125",
              "channel": 2
            },
            {
              "timestamp": 1632426011674181000,
              "snr": -4.800000190734863,
              "signal": -112,
              "packet_hash": "qOK8ETrxcSWBdyLKNBjkYopBeX8b7piwxMFhFRTCfM8",
              "owner": "13VVqYrm4YeBFFu8rwBa3kwgGYkcsuvcLm6fGVhfSVvW2o8udqU",
              "location_hex": "882aaa8421fffff",
              "location": "8c2aaa8421667ff",
              "is_valid": true,
              "gateway": "112L9qP6GRXEhmiH7qkKj6sphUMeXNMxaKuEoMycXco5vbmidme9",
              "frequency": 904.2999877929688,
              "datarate": "SF9BW125",
              "channel": 2
            },
            {
              "timestamp": 1632426011665020400,
              "snr": -13.199999809265137,
              "signal": -111,
              "packet_hash": "qOK8ETrxcSWBdyLKNBjkYopBeX8b7piwxMFhFRTCfM8",
              "owner": "142ooh6JRW8spP7PfRVagqEndSuN3pGcGdZWo5dkPoRRn6EAXTx",
              "location_hex": "882aaa84dbfffff",
              "location": "8c2aaa84da545ff",
              "is_valid": true,
              "gateway": "112iqY2yF2EbKQgxN9nWu2BczqU8qoAYpfrSkUaaea7XEFUWLXgz",
              "frequency": 904.2999877929688,
              "datarate": "SF9BW125",
              "channel": 2
            },
            {
              "timestamp": 1632426009927039200,
              "snr": -13.800000190734863,
              "signal": -116,
              "packet_hash": "qOK8ETrxcSWBdyLKNBjkYopBeX8b7piwxMFhFRTCfM8",
              "owner": "13UfRstRWx9sGxrbrCB5rU2yJ7yxk83TwZ38CBAUjbvN1zGBc8T",
              "location_hex": "882aaa8095fffff",
              "location": "8c2aaa809554bff",
              "is_valid": true,
              "gateway": "11dksEizEv5Q32mY8Qtsy9VVaWLsttoLWgdU6BKrnRba25Xtgpb",
              "frequency": 904.2999877929688,
              "datarate": "SF9BW125",
              "channel": 2
            }
          ],
          "receipt": {
            "tx_power": 0,
            "timestamp": 1632426010451664400,
            "snr": 0,
            "signal": 0,
            "origin": "p2p",
            "gateway": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
            "frequency": 0,
            "datarate": null,
            "data": "GrU",
            "channel": 0
          },
          "geocode": {
            "short_street": "Stumptown Rd",
            "short_state": "VA",
            "short_country": "US",
            "short_city": "Leesburg",
            "long_street": "Stumptown Road",
            "long_state": "Virginia",
            "long_country": "United States",
            "long_city": "Leesburg",
            "city_id": "bGVlc2J1cmd2aXJnaW5pYXVuaXRlZCBzdGF0ZXM"
          },
          "challengee_owner": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt",
          "challengee_lon": -77.53639565293369,
          "challengee_location_hex": "882aaa8269fffff",
          "challengee_location": "8c2aaa8268753ff",
          "challengee_lat": 39.21665905449698,
          "challengee": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK"
        }
      ],
      "onion_key_hash": "RvG4TcKf-KZWCRbzDrAYXkww6lIo0UQENllAhCSOMQ4",
      "height": 1023562,
      "hash": "qt2hw63Sy1irpL1A9f6MoQxQPkHeektyjMPZX2kT69c",
      "fee": 0,
      "challenger_owner": "13zY4XYe3fyBiZmR4zex4oF86DY47p2q3LKu2giDRRsWhVysnSo",
      "challenger_lon": 9.787413897456222,
      "challenger_location": "8c1f15aa599c9ff",
      "challenger_lat": 53.65579988144066,
      "challenger": "11TEymZeRAcX4a7uLSkEheE3FqsPgLjrRbV6L3EcqLbdtsdTgK7"
    },
    {
      "version": 10030002,
      "type": "poc_request_v1",
      "time": 1632426833,
      "secret_hash": "lPK1RGwBDDIYYiPdrIjz24jdXO1NRzQXtqD-AXInuOs",
      "onion_key_hash": "qdYuM-rRy-4r6bHxE0HsTQe1bLGgw6lkIWwA4X5BeTU",
      "height": 1023560,
      "hash": "IJ_3Awa33JMlwzhUcgu-4t_GJK6_5ovZSgrzxrLc9EY",
      "fee": 0,
      "challenger_owner": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt",
      "challenger_location": "8c2aaa8268753ff",
      "challenger": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
      "block_hash": "72MFW1c1HvyC2MsB4JOovPUnE1ZKU2D1YfwvbCxPr_g"
    },
    {
      "type": "rewards_v2",
      "time": 1632415788,
      "start_epoch": 1023337,
      "rewards": [
        {
          "type": "poc_challengers",
          "gateway": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
          "amount": 678175,
          "account": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt"
        }
      ],
      "height": 1023369,
      "hash": "YJbpiwCPj-y29vXeqsw1B4Y-4OsnWmLtjZxVsA7D5iw",
      "end_epoch": 1023368
    },
    {
      "type": "poc_receipts_v1",
      "time": 1632414233,
      "secret": "ACLDpK6nmg1eKEiLkQqaIMVpIVrTTm7laYcM7bTomHIyBB2P_vsrV0pLRDxN0Rx6eQhkTo6DUp-IYnzarIY4iZ09e0hmSOyP3qcrjOzVpNxXTOpYkCr7NO1TZ1WT6QRRjQ4",
      "request_block_hash": "XftRbucsA5BMw3QmDDjVQLk6XZe24aeqXm3iv3qw0h0",
      "path": [
        {
          "witnesses": [
            {
              "timestamp": 1632413226330888400,
              "snr": 8.5,
              "signal": -99,
              "packet_hash": "Z5oskyjoIXm4YKehTFpFKHVJleC5tYqvJU9uuGv5HH4",
              "owner": "13wtfBxAamhLXhrxpyXwqrC9LXBEsrVEyncpPV89RqGBHW64idF",
              "location_hex": "8819683215fffff",
              "location": "8c196832151a1ff",
              "is_valid": false,
              "invalid_reason": "witness_rssi_below_lower_bound",
              "gateway": "112rm5hSz1Q6VN6AvhmGac8wMtB2crTCCL6Z7qyMMWnYWmkkgSHt",
              "frequency": 867.0999755859375,
              "datarate": "SF12BW125",
              "channel": 0
            },
            {
              "timestamp": 1632413226904438800,
              "snr": 4,
              "signal": -106,
              "packet_hash": "Z5oskyjoIXm4YKehTFpFKHVJleC5tYqvJU9uuGv5HH4",
              "owner": "147AZkVEZcSLzcGzrdX9oXWDao2pKkghh4drLQ2s7k6tzAHcLJp",
              "location_hex": "8819683215fffff",
              "location": "8c19683214ec7ff",
              "is_valid": false,
              "invalid_reason": "witness_too_close",
              "gateway": "11ePZFG7YWJ39tMB5FCMgAhCGzBXs6LkJeEHxFKLHHDahkF5UyT",
              "frequency": 867.0999755859375,
              "datarate": "SF12BW125",
              "channel": 0
            },
            {
              "timestamp": 1632413226334567700,
              "snr": -18.5,
              "signal": -117,
              "packet_hash": "Z5oskyjoIXm4YKehTFpFKHVJleC5tYqvJU9uuGv5HH4",
              "owner": "13549kA7LtJ33z1yU2ZzwUQcHS1SPkhTFm2bFMARPX9fnTFbBdu",
              "location_hex": "881968321dfffff",
              "location": "8c1968321d883ff",
              "is_valid": true,
              "gateway": "112mbK6ApE2p27P9NhsiZGeQQEbScMwtYrLWAxV1qsfWnsEeSmkP",
              "frequency": 867.0999755859375,
              "datarate": "SF12BW125",
              "channel": 0
            },
            {
              "timestamp": 1632413226329127400,
              "snr": -0.800000011920929,
              "signal": -114,
              "packet_hash": "Z5oskyjoIXm4YKehTFpFKHVJleC5tYqvJU9uuGv5HH4",
              "owner": "14DYNAMxsvWcnvqt8dZX126j8dEBZzLYAJ9j7DtxLm6fMcCkdqh",
              "location_hex": "8819683213fffff",
              "location": "8c196832122dbff",
              "is_valid": true,
              "gateway": "112vzPXBzqyoSrWLr9x6NRzEFV7cjg2kADPhN9GGpdQoCqtvtMNG",
              "frequency": 867.0999755859375,
              "datarate": "SF12BW125",
              "channel": 0
            },
            {
              "timestamp": 1632413224376567300,
              "snr": -16.200000762939453,
              "signal": -121,
              "packet_hash": "Z5oskyjoIXm4YKehTFpFKHVJleC5tYqvJU9uuGv5HH4",
              "owner": "14DYNAMxsvWcnvqt8dZX126j8dEBZzLYAJ9j7DtxLm6fMcCkdqh",
              "location_hex": "88196832c9fffff",
              "location": "8c196832c918dff",
              "is_valid": true,
              "gateway": "112Xz9MHLtivY6xgVxBfbzQaV2Dzh7gdhVE2E3e9yhX4suczRvJq",
              "frequency": 867.0999755859375,
              "datarate": "SF12BW125",
              "channel": 0
            },
            {
              "timestamp": 1632413226330442500,
              "snr": 8,
              "signal": -95,
              "packet_hash": "Z5oskyjoIXm4YKehTFpFKHVJleC5tYqvJU9uuGv5HH4",
              "owner": "13uExhAK2zjmmFH71EtEZVpt7sDaYZKTLpKAyRAKHEAhUHrV5kz",
              "location_hex": "8819683217fffff",
              "location": "8c19683217b3dff",
              "is_valid": true,
              "gateway": "112HmY3PwFBaESNzdgSX6ouh5UdsWFTgU9RvFUWyCDjGBSTS2htW",
              "frequency": 867.0999755859375,
              "datarate": "SF12BW125",
              "channel": 0
            },
            {
              "timestamp": 1632413226329093600,
              "snr": -6.800000190734863,
              "signal": -115,
              "packet_hash": "Z5oskyjoIXm4YKehTFpFKHVJleC5tYqvJU9uuGv5HH4",
              "owner": "14DYNAMxsvWcnvqt8dZX126j8dEBZzLYAJ9j7DtxLm6fMcCkdqh",
              "location_hex": "881968ad23fffff",
              "location": "8c1968ad22b61ff",
              "is_valid": true,
              "gateway": "11qFGscLoZ33n7tBYR7fT5fshPpYnA7bRAiNZqJMDvnAg2qQVux",
              "frequency": 867.0999755859375,
              "datarate": "SF12BW125",
              "channel": 0
            },
            {
              "timestamp": 1632413224877203500,
              "snr": 4.800000190734863,
              "signal": -107,
              "packet_hash": "Z5oskyjoIXm4YKehTFpFKHVJleC5tYqvJU9uuGv5HH4",
              "owner": "13CijJkXY32mFE2rrEvN3UbuW7BfknmX1Q9qyoRqa7GknQE1wPQ",
              "location_hex": "8819683215fffff",
              "location": "8c19683214415ff",
              "is_valid": false,
              "invalid_reason": "witness_too_close",
              "gateway": "112YwncrEjZg3iXg3avmFqFwvEKfybwVZzymou81FCA4TbZwKRxt",
              "frequency": 867.0999755859375,
              "datarate": "SF12BW125",
              "channel": 0
            },
            {
              "timestamp": 1632413226330943500,
              "snr": -10.5,
              "signal": -109,
              "packet_hash": "Z5oskyjoIXm4YKehTFpFKHVJleC5tYqvJU9uuGv5HH4",
              "owner": "14Egw3AwM3BFyHnDdLCSiMbbw9zxiJ6BVZyNgRXzQT7DkeFQtSq",
              "location_hex": "88196832c5fffff",
              "location": "8c196832c4cb9ff",
              "is_valid": true,
              "gateway": "11vPAh63j5r4kdTJ9g1Vss58meWCBkGJHgYgLK6x6FaZWiDTwDt",
              "frequency": 867.0999755859375,
              "datarate": "SF12BW125",
              "channel": 0
            },
            {
              "timestamp": 1632413226332651500,
              "snr": -12.5,
              "signal": -117,
              "packet_hash": "Z5oskyjoIXm4YKehTFpFKHVJleC5tYqvJU9uuGv5HH4",
              "owner": "147Ao9QkGjLHUeDoZR1Y2aRXofL3Dk3QD6GzubcPAyyneE2ZpvZ",
              "location_hex": "881968ad35fffff",
              "location": "8c1968ad34605ff",
              "is_valid": true,
              "gateway": "11iWaFHzYvDCKgGXD9TLoUHG69A38nse97v1uujWycrB5vVrrxe",
              "frequency": 867.0999755859375,
              "datarate": "SF12BW125",
              "channel": 0
            }
          ],
          "receipt": {
            "tx_power": 0,
            "timestamp": 1632413222754133000,
            "snr": 0,
            "signal": 0,
            "origin": "p2p",
            "gateway": "112KhPSzzLi5Dpx4Boc8JjyPjuV8pRdK8HLM1hyJP454Mce6kMM",
            "frequency": 0,
            "datarate": null,
            "data": "MFI",
            "channel": 0
          },
          "geocode": {
            "short_street": "Westfalenstraat",
            "short_state": "NH",
            "short_country": "NL",
            "short_city": "Alkmaar",
            "long_street": "Westfalenstraat",
            "long_state": "Noord-Holland",
            "long_country": "Netherlands",
            "long_city": "Alkmaar",
            "city_id": "YWxrbWFhcm5vb3JkLWhvbGxhbmRuZXRoZXJsYW5kcw"
          },
          "challengee_owner": "13VcQ3EEFtN39UGZkjnP9ww9AHwgb4pwVniKpHBjgwRtaGUMevA",
          "challengee_lon": 4.757355055721787,
          "challengee_location_hex": "8819683215fffff",
          "challengee_location": "8c196832146ebff",
          "challengee_lat": 52.66685608872497,
          "challengee": "112KhPSzzLi5Dpx4Boc8JjyPjuV8pRdK8HLM1hyJP454Mce6kMM"
        }
      ],
      "onion_key_hash": "c47EirQ1o4smB0pKTKb-ZqwoEcpliY0Ohty-660kprY",
      "height": 1023339,
      "hash": "6CcxHLQ5jd3Y07cp6YC-s3xVtpHOrqtGQD8utBy7U7A",
      "fee": 0,
      "challenger_owner": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt",
      "challenger_lon": -77.53639565293369,
      "challenger_location": "8c2aaa8268753ff",
      "challenger_lat": 39.21665905449698,
      "challenger": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK"
    },
    {
      "version": 10030002,
      "type": "poc_request_v1",
      "time": 1632412882,
      "secret_hash": "Qw6A5ZdNxo0P7-oYSF7dsRZ9BCRdO8LOoTrA-1wGSYI",
      "onion_key_hash": "c47EirQ1o4smB0pKTKb-ZqwoEcpliY0Ohty-660kprY",
      "height": 1023313,
      "hash": "fgBFe6AgRaEhhBn46LEtkHqqwFTGXMJnXuDcAPsxKi0",
      "fee": 0,
      "challenger_owner": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt",
      "challenger_location": "8c2aaa8268753ff",
      "challenger": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
      "block_hash": "tN00Y9cUoqSEtqyXAZF1-y8wbo-iylaBY7vg15ELOUk"
    },
    {
      "type": "poc_receipts_v1",
      "time": 1632406600,
      "secret": "AA_7SYOib95FCvY949gW--TDmLygYQLBtUqvcbXpfunhBB47NkLa4KLjJURcv1qUSQc9czIGmT7PGaVfGPyK3W7GHgP1uBgWWVXSf8Oe89BQ6HjNewK-aLC-v6TnuV-3XB8",
      "request_block_hash": "Lvao9qVshVF0rvyVMg5IMbrobsEGS9g74aKnljVXR4g",
      "path": [
        {
          "witnesses": [],
          "receipt": {
            "tx_power": 0,
            "timestamp": 1632405723838919700,
            "snr": 0,
            "signal": 0,
            "origin": "p2p",
            "gateway": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
            "frequency": 0,
            "datarate": null,
            "data": "h38",
            "channel": 0
          },
          "geocode": {
            "short_street": "Stumptown Rd",
            "short_state": "VA",
            "short_country": "US",
            "short_city": "Leesburg",
            "long_street": "Stumptown Road",
            "long_state": "Virginia",
            "long_country": "United States",
            "long_city": "Leesburg",
            "city_id": "bGVlc2J1cmd2aXJnaW5pYXVuaXRlZCBzdGF0ZXM"
          },
          "challengee_owner": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt",
          "challengee_lon": -77.53639565293369,
          "challengee_location_hex": "882aaa8269fffff",
          "challengee_location": "8c2aaa8268753ff",
          "challengee_lat": 39.21665905449698,
          "challengee": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK"
        }
      ],
      "onion_key_hash": "aPnoauwxe_Yi0FsM0h80FqObVP1-lu9paUlNfBYyfhw",
      "height": 1023200,
      "hash": "G9yIBcWHAJp3TIiiqabQqLLiW1cWCNxpd-FYgAQ0CXA",
      "fee": 0,
      "challenger_owner": "13FCmP8BeLCojKjUwSY2RHaKfK6wjzZDkz22P9DMuoKuuTidCEh",
      "challenger_lon": -84.28750188212047,
      "challenger_location": "8c44c1318d16dff",
      "challenger_lat": 33.91727612784748,
      "challenger": "11UMasSfidH27f96CJE2dtzjddRb4DTKG1CSWKHqxDwGd78Ht84"
    },
    {
      "version": 10030002,
      "type": "poc_request_v1",
      "time": 1632396554,
      "secret_hash": "E1TkvicQEPE-EjaWYkaBLqvRAcyJRFd5ryAmYKIBOtU",
      "onion_key_hash": "Ln2fBa3CJdYT28GC7I48WlS7GlzOGIIYUWhp2uCrEEQ",
      "height": 1023014,
      "hash": "6sVmHs1xzExfaY-0AeUqk0lqNnrP1brJy6Rz3LU0ESE",
      "fee": 0,
      "challenger_owner": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt",
      "challenger_location": "8c2aaa8268753ff",
      "challenger": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
      "block_hash": "Xb_lC0tNuniPEs3JEfD1ZFLuJoREq8m4x-jWbTwL6X8"
    },
    {
      "type": "rewards_v2",
      "time": 1632383551,
      "start_epoch": 1022741,
      "rewards": [
        {
          "type": "poc_challengees",
          "gateway": "112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK",
          "amount": 4333595,
          "account": "1359NhpbxJg1jRpDenJvrmD2P3ZN3hWGSGzUF6Uyn828zYdyYVt"
        }
      ],
      "height": 1022773,
      "hash": "G-Bf54kqmprh6TSDiLD0Y6H8Cie-sY8idkdMgwAJK6c",
      "end_epoch": 1022772
    }
  ]
}

Currently, what I'm doing to get the data I need is something like this:

a="112VEhPPMYF95neEEwwgnckHej4bgZ1roo13SMx18RSJxLq6JuiK"

this_data="$(jq -r --arg a "${a}" '.data[] | select(.type == "poc_receipts_v1") | select(.challengee != null) | select(.challengee == $a)' file.json)
$(jq -r --arg a "${a}" '.data[] | select(.type == "poc_receipts_v1") | select(.path[].challengee != null) | select(.path[].challengee == $a)' file.json)"

So I'm running 2 JQ queries to get the values that I'm looking for, which is taxing on CPU since the json file is pretty large. It would be nice to do this in a single JQ query so I dont need to re-read the file on the second query.

Thanks,

CodePudding user response:

You could join both calls into one by producing two outputs with the requests separated by comma

(
  .data[]
  | select(.type == "poc_receipts_v1")
  | select(.challengee != null)
  | select(.challengee == $a)
),
(
  .data[]
  | select(.type == "poc_receipts_v1")
  | select(.path[].challengee != null)
  | select(.path[].challengee == $a)
)

However, as your requests basically accomplish the same task just in different locations, you could factor them out, simplifying it to

.data[]
| select(.type == "poc_receipts_v1")
| select((.,.path[]).challengee != null)
| select((.,.path[]).challengee == $a)

Also, if you provide $a via the --arg parameter, you could also skip testing against null as the string may only be empty but never null.

  • Related