计数带字符串的项目

时间:2019-05-06 07:17:06

标签: json count jq

我需要计算有多少个MAC地址存在文档级别的损害

我试图从该网站的另一个示例中解决此过滤器,但是问题是我需要计算有多少个MAC地址的损害名称为“ docsis-level”

[
  {
    "mac": "BC:2E:48:D7:E6:EF",
    "timestamp": "2019-05-06T06:06:13.568Z",
    "impairments": [
      {
        "name": "level",
        "impaired": true,
        "startFrequency": 76.279,
        "stopFrequency": 953.721,
        "level": 52.4
      },
      {
        "name": "tilt",
        "impaired": false,
        "startFrequency": 123,
        "stopFrequency": 795,
        "level": 8.28
      },
      {
        "name": "roll-off",
        "impaired": false,
        "startFrequency": 699,
        "stopFrequency": 795,
        "level": 0
      },
      {
        "name": "suck-out",
        "impaired": false,
        "startFrequency": 0,
        "stopFrequency": 0,
        "level": 0
      },
      {
        "name": "peak",
        "impaired": false,
        "startFrequency": 0,
        "stopFrequency": 0,
        "level": 0
      },
      {
        "name": "ripple",
        "impaired": true,
        "startFrequency": 119.932,
        "stopFrequency": 798.037,
        "level": 0
      },
      {
        "name": "fm-ingress",
        "impaired": false,
        "startFrequency": 0,
        "stopFrequency": 0,
        "level": 0
      },
      {
        "name": "lte-ingress",
        "impaired": false,
        "startFrequency": 0,
        "stopFrequency": 0,
        "level": 0
      },
      {
        "name": "adjacency",
        "impaired": false,
        "startFrequency": 179.982,
        "stopFrequency": 186.018,
        "level": 1.3
      },
      {
        "name": "channel-snr",
        "impaired": false,
        "startFrequency": 141.025,
        "stopFrequency": 141.025,
        "level": 33.7
      },
      {
        "name": "channel-level",
        "impaired": true,
        "startFrequency": 639.014,
        "stopFrequency": 639.014,
        "level": 27.47
      },
      {
        "name": "channel-tilt",
        "impaired": false,
        "startFrequency": 165.107,
        "stopFrequency": 165.107,
        "level": 1.21
      },
      {
        "name": "channel-icfr",
        "impaired": false,
        "startFrequency": 752.803,
        "stopFrequency": 752.803,
        "level": 6.4
      },
      {
        "name": "channel-guard-band",
        "impaired": true,
        "startFrequency": 531.025,
        "stopFrequency": 531.025,
        "level": -32.33
      },
      {
        "name": "correctable-cer",
        "impaired": false,
        "startFrequency": 603,
        "stopFrequency": 603,
        "level": 0
      },
      {
        "name": "uncorrectable-cer",
        "impaired": false,
        "startFrequency": 603,
        "stopFrequency": 603,
        "level": 0
      },
      {
        "name": "docsis-snr",
        "impaired": false,
        "startFrequency": 639,
        "stopFrequency": 639,
        "level": 38.9
      },
      {
        "name": "docsis-level",
        "impaired": false,
        "startFrequency": 633,
        "stopFrequency": 633,
        "level": 7.8
      }
    ],
    "ofdmData": {
      "numChannels": 0,
      "numProfiles": 0
    }
  },
  {
    "mac": "BC:2E:48:D7:EA:24",
    "timestamp": "2019-05-06T06:06:13.536Z",
    "impairments": [
      {
        "name": "level",
        "impaired": true,
        "startFrequency": 76.279,
        "stopFrequency": 953.721,
        "level": 52.6
      },
      {
        "name": "tilt",
        "impaired": false,
        "startFrequency": 123,
        "stopFrequency": 795,
        "level": 8.69
      },
      {
        "name": "roll-off",
        "impaired": false,
        "startFrequency": 699,
        "stopFrequency": 795,
        "level": 0
      },
      {
        "name": "suck-out",
        "impaired": false,
        "startFrequency": 0,
        "stopFrequency": 0,
        "level": 0
      },
      {
        "name": "peak",
        "impaired": false,
        "startFrequency": 0,
        "stopFrequency": 0,
        "level": 0
      },
      {
        "name": "ripple",
        "impaired": false,
        "startFrequency": 0,
        "stopFrequency": 0,
        "level": 0
      },
      {
        "name": "fm-ingress",
        "impaired": false,
        "startFrequency": 0,
        "stopFrequency": 0,
        "level": 0
      },
      {
        "name": "lte-ingress",
        "impaired": false,
        "startFrequency": 0,
        "stopFrequency": 0,
        "level": 0
      },
      {
        "name": "adjacency",
        "impaired": false,
        "startFrequency": 179.982,
        "stopFrequency": 186.018,
        "level": 1.4
      },
      {
        "name": "channel-snr",
        "impaired": false,
        "startFrequency": 141.025,
        "stopFrequency": 141.025,
        "level": 36.1
      },
      {
        "name": "channel-level",
        "impaired": true,
        "startFrequency": 639.014,
        "stopFrequency": 639.014,
        "level": 27.46
      },
      {
        "name": "channel-tilt",
        "impaired": false,
        "startFrequency": 687.002,
        "stopFrequency": 687.002,
        "level": 0.65
      },
      {
        "name": "channel-icfr",
        "impaired": false,
        "startFrequency": 392.861,
        "stopFrequency": 392.861,
        "level": 5.4
      },
      {
        "name": "channel-guard-band",
        "impaired": true,
        "startFrequency": 507.061,
        "stopFrequency": 507.061,
        "level": -32.9
      },
      {
        "name": "correctable-cer",
        "impaired": false,
        "startFrequency": 693,
        "stopFrequency": 693,
        "level": 0
      },
      {
        "name": "uncorrectable-cer",
        "impaired": false,
        "startFrequency": 693,
        "stopFrequency": 693,
        "level": 0
      },
      {
        "name": "docsis-snr",
        "impaired": false,
        "startFrequency": 651,
        "stopFrequency": 651,
        "level": 39.3
      },
      {
        "name": "docsis-level",
        "impaired": false,
        "startFrequency": 651,
        "stopFrequency": 651,
        "level": 8
      }
    ],
    "ofdmData": {
      "numChannels": 0,
      "numProfiles": 0
    }
  },
  {
    "mac": "B0:39:56:4B:B2:38",
    "timestamp": "2019-05-06T05:05:34Z",
    "impairments": [
      {
        "name": "channel-snr",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-level",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-tilt",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-icfr",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-guard-band",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "correctable-cer",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "uncorrectable-cer",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "docsis-snr",
        "impaired": false,
        "startFrequency": 645,
        "stopFrequency": 645,
        "level": 39
      },
      {
        "name": "docsis-level",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": -5.9
      },
      {
        "name": "ofdm-mer-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 38.85
      },
      {
        "name": "ofdm-mer-sd",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.58
      },
      {
        "name": "ofdm-amp-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.02
      },
      {
        "name": "ofdm-amp-rms",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.4
      },
      {
        "name": "ofdm-amp-slope",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": -0.013
      },
      {
        "name": "ofdm-amp-pk-pk",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 2.93
      },
      {
        "name": "ofdm-gd-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 1778
      },
      {
        "name": "ofdm-gd-rms",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 17.26
      },
      {
        "name": "ofdm-gd-slope",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.029
      },
      {
        "name": "ofdm-gd-pk-pk",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 86.79
      },
      {
        "name": "ofdm-plc-cwer",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0
      },
      {
        "name": "ofdm-ncp-fail",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0
      }
    ],
    "ofdmData": {
      "numChannels": 1,
      "numProfiles": 4
    }
  },
  {
    "mac": "B0:39:56:4C:BF:40",
    "timestamp": "2019-05-06T05:05:34Z",
    "impairments": [
      {
        "name": "channel-snr",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-level",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-tilt",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-icfr",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-guard-band",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "correctable-cer",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "uncorrectable-cer",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "docsis-snr",
        "impaired": false,
        "startFrequency": 675,
        "stopFrequency": 675,
        "level": 39.9
      },
      {
        "name": "docsis-level",
        "impaired": false,
        "startFrequency": 615,
        "stopFrequency": 615,
        "level": 6.9
      },
      {
        "name": "ofdm-mer-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 40.07
      },
      {
        "name": "ofdm-mer-sd",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.58
      },
      {
        "name": "ofdm-amp-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": -0.03
      },
      {
        "name": "ofdm-amp-rms",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.39
      },
      {
        "name": "ofdm-amp-slope",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.002
      },
      {
        "name": "ofdm-amp-pk-pk",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 2.06
      },
      {
        "name": "ofdm-gd-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 1882
      },
      {
        "name": "ofdm-gd-rms",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 9.14
      },
      {
        "name": "ofdm-gd-slope",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.032
      },
      {
        "name": "ofdm-gd-pk-pk",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 62.88
      },
      {
        "name": "ofdm-plc-cwer",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0
      },
      {
        "name": "ofdm-ncp-fail",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0
      }
    ],
    "ofdmData": {
      "numChannels": 1,
      "numProfiles": 4
    }
  },
  {
    "mac": "A0:04:60:FC:8F:90",
    "timestamp": "2019-05-06T05:05:34Z",
    "impairments": [
      {
        "name": "channel-snr",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "channel-level",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "channel-tilt",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "channel-icfr",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "channel-guard-band",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "correctable-cer",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "uncorrectable-cer",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "docsis-snr",
        "impaired": false,
        "startFrequency": 645,
        "stopFrequency": 645,
        "level": 39.3
      },
      {
        "name": "docsis-level",
        "impaired": false,
        "startFrequency": 609,
        "stopFrequency": 609,
        "level": 12.4
      },
      {
        "name": "ofdm-mer-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 39.84
      },
      {
        "name": "ofdm-mer-sd",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.58
      },
      {
        "name": "ofdm-amp-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": -0.03
      },
      {
        "name": "ofdm-amp-rms",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.42
      },
      {
        "name": "ofdm-amp-slope",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.011
      },
      {
        "name": "ofdm-amp-pk-pk",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 2.37
      },
      {
        "name": "ofdm-gd-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 1807
      },
      {
        "name": "ofdm-gd-rms",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 9.49
      },
      {
        "name": "ofdm-gd-slope",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.027
      },
      {
        "name": "ofdm-gd-pk-pk",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 65.65
      },
      {
        "name": "ofdm-plc-cwer",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0
      },
      {
        "name": "ofdm-ncp-fail",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0
      }
    ],
    "ofdmData": {
      "numChannels": 1,
      "numProfiles": 4
    }
  },
  {
    "mac": "B0:DA:F9:11:CD:25",
    "timestamp": "2019-05-06T05:05:34Z",
    "impairments": [
      {
        "name": "channel-snr",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-level",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-tilt",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-icfr",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "channel-guard-band",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "correctable-cer",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "uncorrectable-cer",
        "impaired": false,
        "startFrequency": 663,
        "stopFrequency": 663,
        "level": 0
      },
      {
        "name": "docsis-snr",
        "impaired": false,
        "startFrequency": 645,
        "stopFrequency": 645,
        "level": 37.9
      },
      {
        "name": "docsis-level",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": -11.1
      },
      {
        "name": "ofdm-mer-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 37.58
      },
      {
        "name": "ofdm-mer-sd",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.63
      },
      {
        "name": "ofdm-amp-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": -0.03
      },
      {
        "name": "ofdm-amp-rms",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.49
      },
      {
        "name": "ofdm-amp-slope",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": -0.013
      },
      {
        "name": "ofdm-amp-pk-pk",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 3.21
      },
      {
        "name": "ofdm-gd-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 1839
      },
      {
        "name": "ofdm-gd-rms",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 17.59
      },
      {
        "name": "ofdm-gd-slope",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.027
      },
      {
        "name": "ofdm-gd-pk-pk",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 95.32
      },
      {
        "name": "ofdm-plc-cwer",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0
      },
      {
        "name": "ofdm-ncp-fail",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0
      }
    ],
    "ofdmData": {
      "numChannels": 1,
      "numProfiles": 4
    }
  },
  {
    "mac": "D4:0A:A9:00:00:F1",
    "timestamp": "2019-05-06T05:05:34Z",
    "impairments": [
      {
        "name": "channel-snr",
        "impaired": false,
        "startFrequency": 621,
        "stopFrequency": 621,
        "level": 0
      },
      {
        "name": "channel-level",
        "impaired": false,
        "startFrequency": 621,
        "stopFrequency": 621,
        "level": 0
      },
      {
        "name": "channel-tilt",
        "impaired": false,
        "startFrequency": 621,
        "stopFrequency": 621,
        "level": 0
      },
      {
        "name": "channel-icfr",
        "impaired": false,
        "startFrequency": 621,
        "stopFrequency": 621,
        "level": 0
      },
      {
        "name": "channel-guard-band",
        "impaired": false,
        "startFrequency": 621,
        "stopFrequency": 621,
        "level": 0
      },
      {
        "name": "correctable-cer",
        "impaired": false,
        "startFrequency": 621,
        "stopFrequency": 621,
        "level": 0
      },
      {
        "name": "uncorrectable-cer",
        "impaired": false,
        "startFrequency": 621,
        "stopFrequency": 621,
        "level": 0
      },
      {
        "name": "docsis-snr",
        "impaired": false,
        "startFrequency": 639,
        "stopFrequency": 639,
        "level": 37.3
      },
      {
        "name": "docsis-level",
        "impaired": false,
        "startFrequency": 615,
        "stopFrequency": 615,
        "level": 11.6
      }
    ],
    "ofdmData": {
      "numChannels": 0,
      "numProfiles": 0
    }
  },
  {
    "mac": "B0:39:56:4B:B1:F8",
    "timestamp": "2019-05-06T05:05:34Z",
    "impairments": [
      {
        "name": "channel-snr",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "channel-level",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "channel-tilt",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "channel-icfr",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "channel-guard-band",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "correctable-cer",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "uncorrectable-cer",
        "impaired": false,
        "startFrequency": 669,
        "stopFrequency": 669,
        "level": 0
      },
      {
        "name": "docsis-snr",
        "impaired": false,
        "startFrequency": 675,
        "stopFrequency": 675,
        "level": 39.4
      },
      {
        "name": "docsis-level",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 4.4
      },
      {
        "name": "ofdm-mer-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 39.44
      },
      {
        "name": "ofdm-mer-sd",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.61
      },
      {
        "name": "ofdm-amp-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": -0.13
      },
      {
        "name": "ofdm-amp-rms",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.72
      },
      {
        "name": "ofdm-amp-slope",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.004
      },
      {
        "name": "ofdm-amp-pk-pk",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 3.42
      },
      {
        "name": "ofdm-gd-mean",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 1851
      },
      {
        "name": "ofdm-gd-rms",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 8.59
      },
      {
        "name": "ofdm-gd-slope",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0.026
      },
      {
        "name": "ofdm-gd-pk-pk",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 58.58
      },
      {
        "name": "ofdm-plc-cwer",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0
      },
      {
        "name": "ofdm-ncp-fail",
        "impaired": false,
        "startFrequency": 811,
        "stopFrequency": 904.95,
        "level": 0
      }
    ],
    "ofdmData": {
      "numChannels": 1,
      "numProfiles": 4
    }
  }
]

文档数= x数的mac数

3 个答案:

答案 0 :(得分:0)

让我为您提供基于JSON步行路径Unix工具的解决方案: jtc -在此处将查询逻辑“编码”到路径中。

1。您的JSON格式有误(您可以使用jtc -d在发布的JSON中查看问题所在)

2。修复JSON后,此cli将计算impairments包含记录"name": "docsis-level"的所有MAC:

bash $ <file.json jtc -w'<mac>l:[-1] [impairments][name]:<docsis-level>' -r | wc -l
       8
bash $ 

步行路径(-w)的说明:

  • <mac>l:[-1]-查找每个带有标签mac的记录,并从找到的条目中以JSON的方式升级第1步
  • [impairments][name]:<docsis-level>-地址记录impairments,并在其中找到记录"name": "docsis-level"
  • 如果以上所有步骤均成功-打印找到的条目

wc -l将计算收集的(成功的)步行路程

PS>披露:我是jtc工具的创建者

答案 1 :(得分:0)

我将您的json文件上传到了“ http://www.json-generator.com/api/json/get/cggsimUEBK?indent=2”,下面的代码应为您计数。只需在开发控制台中运行它即可。

function findCount(){  
  var result = json.responseJSON;
  var count=0;
  result.forEach(function(item){
   var impairments = item.impairments;
     impairments.forEach(function(impairment){
        if((impairment['name'] == "docsis-level")){ count++;}
     });
   });
  console.log(count);
  alert(count);  
}
var json = $.getJSON("http://www.json-generator.com/api/json/get/cggsimUEBK?indent=2",findCount);

答案 2 :(得分:0)

在jq中进行计数的最简单方法是为此使用函数:

def count(stream): reduce stream as $i (0; .+1);

此定义还支持在时间和空间方面均有效的解决方案。

由于问题中的JSON格式错误,我将提出两种解决方案-一种基于具有“受损”键的对象:

count(.. | objects | select( has("impaired") and .name == "docsis-level"))

和另一个基于“障碍”数组的

count(.. | .impairments? // empty | .[] | select( .name? == "docsis-level"))

这两个查询说明了实现不同程度的鲁棒性的不同样式,但都与相关对象在输入中的位置无关。

附录

现在示例数据已被修改,可以提供以下取决于常规结构的解决方案:

count(.[] | .impairments[] | select( .name == "docsis-level"))