如何在使用jq维护结构的同时过滤JSON中的嵌套数组

时间:2019-11-09 02:23:19

标签: json jq

我的JSON结构如下:

{
  "GAME_ID": "0021900121",
  "HOME_TEAM_ID": 1610612740,
  "AWAY_TEAM_ID": 1610612761,
  "GAMECODE": "20191108/TORNOP",
  "SEASON": "2019",
  "HOME_ROSTER": [
    {
      "PLAYER_ID": 1629638,
      "NAME": "Nickeil Alexander-Walker",
      "JERSEY_NUMBER": "0",
      "POSITION": "G",
      "HEIGHT": "6-5",
      "WEIGHT": "205",
      "BIRTHDAY": "SEP 02, 1998",
      "AGE": 21,
      "EXPERIENCE": "R",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": 12.5,
          "POINTS": 4.3,
          "FIELD_GOAL_PERCENTAGE": 0.239,
          "OFFENSIVE_REBOUNDS": 0.3,
          "DEFENSIVE_REBOUNDS": 2,
          "ASSISTS": 2.9,
          "TURNOVERS": 0.6,
          "STEALS": 0.4,
          "BLOCKS": 0
        },
        {
          "DATE": "NOV 04, 2019",
          "MATCHUP": "NOP @ BKN",
          "MINUTES": 4,
          "POINTS": 0,
          "FIELD_GOAL_PERCENTAGE": 0,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 0,
          "ASSISTS": 0,
          "TURNOVERS": 0,
          "STEALS": 0,
          "BLOCKS": 0
        },
        {
          "DATE": "NOV 02, 2019",
          "MATCHUP": "NOP @ OKC",
          "MINUTES": 8,
          "POINTS": 4,
          "FIELD_GOAL_PERCENTAGE": 0.2,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 1,
          "ASSISTS": 0,
          "TURNOVERS": 0,
          "STEALS": 0,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 31, 2019",
          "MATCHUP": "NOP vs. DEN",
          "MINUTES": 12,
          "POINTS": 0,
          "FIELD_GOAL_PERCENTAGE": 0,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 4,
          "ASSISTS": 3,
          "TURNOVERS": 0,
          "STEALS": 0,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 28, 2019",
          "MATCHUP": "NOP vs. GSW",
          "MINUTES": 24,
          "POINTS": 15,
          "FIELD_GOAL_PERCENTAGE": 0.545,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 4,
          "ASSISTS": 9,
          "TURNOVERS": 1,
          "STEALS": 1,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 26, 2019",
          "MATCHUP": "NOP @ HOU",
          "MINUTES": 12,
          "POINTS": 2,
          "FIELD_GOAL_PERCENTAGE": 0.25,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 1,
          "ASSISTS": 0,
          "TURNOVERS": 1,
          "STEALS": 0,
          "BLOCKS": 0
        }
      ]
    },
    {
      "PLAYER_ID": 1629627,
      "NAME": "Zion Williamson",
      "JERSEY_NUMBER": "1",
      "POSITION": "F",
      "HEIGHT": "6-6",
      "WEIGHT": "284",
      "BIRTHDAY": "JUL 06, 2000",
      "AGE": 19,
      "EXPERIENCE": "R",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": "N/A",
          "POINTS": "N/A",
          "FIELD_GOAL_PERCENTAGE": "N/A",
          "OFFENSIVE_REBOUNDS": "N/A",
          "DEFENSIVE_REBOUNDS": "N/A",
          "ASSISTS": "N/A",
          "TURNOVERS": "N/A",
          "STEALS": "N/A",
          "BLOCKS": "N/A"
        }
      ]
    },
    {
      "PLAYER_ID": 1628366,
      "NAME": "Lonzo Ball",
      "JERSEY_NUMBER": "2",
      "POSITION": "G",
      "HEIGHT": "6-6",
      "WEIGHT": "190",
      "BIRTHDAY": "OCT 27, 1997",
      "AGE": 22,
      "EXPERIENCE": "2",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": 30,
          "POINTS": 12.4,
          "FIELD_GOAL_PERCENTAGE": 0.432,
          "OFFENSIVE_REBOUNDS": 0.7,
          "DEFENSIVE_REBOUNDS": 3.9,
          "ASSISTS": 6.7,
          "TURNOVERS": 2.1,
          "STEALS": 1.6,
          "BLOCKS": 0.1
        },
        {
          "DATE": "NOV 04, 2019",
          "MATCHUP": "NOP @ BKN",
          "MINUTES": 21,
          "POINTS": 15,
          "FIELD_GOAL_PERCENTAGE": 0.6,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 1,
          "ASSISTS": 3,
          "TURNOVERS": 2,
          "STEALS": 0,
          "BLOCKS": 0
        },
        {
          "DATE": "NOV 02, 2019",
          "MATCHUP": "NOP @ OKC",
          "MINUTES": 33,
          "POINTS": 10,
          "FIELD_GOAL_PERCENTAGE": 0.364,
          "OFFENSIVE_REBOUNDS": 2,
          "DEFENSIVE_REBOUNDS": 6,
          "ASSISTS": 7,
          "TURNOVERS": 5,
          "STEALS": 3,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 31, 2019",
          "MATCHUP": "NOP vs. DEN",
          "MINUTES": 32,
          "POINTS": 9,
          "FIELD_GOAL_PERCENTAGE": 0.571,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 3,
          "ASSISTS": 8,
          "TURNOVERS": 3,
          "STEALS": 1,
          "BLOCKS": 1
        },
        {
          "DATE": "OCT 28, 2019",
          "MATCHUP": "NOP vs. GSW",
          "MINUTES": 31,
          "POINTS": 12,
          "FIELD_GOAL_PERCENTAGE": 0.4,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 3,
          "ASSISTS": 9,
          "TURNOVERS": 2,
          "STEALS": 2,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 26, 2019",
          "MATCHUP": "NOP @ HOU",
          "MINUTES": 36,
          "POINTS": 18,
          "FIELD_GOAL_PERCENTAGE": 0.462,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 2,
          "ASSISTS": 10,
          "TURNOVERS": 0,
          "STEALS": 3,
          "BLOCKS": 0
        }
      ]
    },
    {
      "PLAYER_ID": 1628404,
      "NAME": "Josh Hart",
      "JERSEY_NUMBER": "3",
      "POSITION": "G",
      "HEIGHT": "6-5",
      "WEIGHT": "215",
      "BIRTHDAY": "MAR 06, 1995",
      "AGE": 24,
      "EXPERIENCE": "2",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": 29.6,
          "POINTS": 13.6,
          "FIELD_GOAL_PERCENTAGE": 0.465,
          "OFFENSIVE_REBOUNDS": 1.7,
          "DEFENSIVE_REBOUNDS": 5.9,
          "ASSISTS": 1.1,
          "TURNOVERS": 1.6,
          "STEALS": 1.4,
          "BLOCKS": 0.6
        },
        {
          "DATE": "NOV 04, 2019",
          "MATCHUP": "NOP @ BKN",
          "MINUTES": 31,
          "POINTS": 14,
          "FIELD_GOAL_PERCENTAGE": 0.462,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 6,
          "ASSISTS": 1,
          "TURNOVERS": 3,
          "STEALS": 4,
          "BLOCKS": 0
        },
        {
          "DATE": "NOV 02, 2019",
          "MATCHUP": "NOP @ OKC",
          "MINUTES": 30,
          "POINTS": 12,
          "FIELD_GOAL_PERCENTAGE": 0.455,
          "OFFENSIVE_REBOUNDS": 3,
          "DEFENSIVE_REBOUNDS": 12,
          "ASSISTS": 3,
          "TURNOVERS": 1,
          "STEALS": 1,
          "BLOCKS": 1
        },
        {
          "DATE": "OCT 31, 2019",
          "MATCHUP": "NOP vs. DEN",
          "MINUTES": 27,
          "POINTS": 3,
          "FIELD_GOAL_PERCENTAGE": 0.333,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 4,
          "ASSISTS": 1,
          "TURNOVERS": 1,
          "STEALS": 0,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 28, 2019",
          "MATCHUP": "NOP vs. GSW",
          "MINUTES": 31,
          "POINTS": 12,
          "FIELD_GOAL_PERCENTAGE": 0.444,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 3,
          "ASSISTS": 1,
          "TURNOVERS": 2,
          "STEALS": 1,
          "BLOCKS": 1
        },
        {
          "DATE": "OCT 26, 2019",
          "MATCHUP": "NOP @ HOU",
          "MINUTES": 34,
          "POINTS": 23,
          "FIELD_GOAL_PERCENTAGE": 0.471,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 3,
          "ASSISTS": 1,
          "TURNOVERS": 1,
          "STEALS": 2,
          "BLOCKS": 1
        }
      ]
    },
    {
      "PLAYER_ID": 200755,
      "NAME": "JJ Redick",
      "JERSEY_NUMBER": "4",
      "POSITION": "G",
      "HEIGHT": "6-3",
      "WEIGHT": "200",
      "BIRTHDAY": "JUN 24, 1984",
      "AGE": 35,
      "EXPERIENCE": "13",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": 23.9,
          "POINTS": 10.6,
          "FIELD_GOAL_PERCENTAGE": 0.393,
          "OFFENSIVE_REBOUNDS": 0.3,
          "DEFENSIVE_REBOUNDS": 1.3,
          "ASSISTS": 1.4,
          "TURNOVERS": 1.7,
          "STEALS": 0.3,
          "BLOCKS": 0.4
        },
        {
          "DATE": "NOV 04, 2019",
          "MATCHUP": "NOP @ BKN",
          "MINUTES": 21,
          "POINTS": 12,
          "FIELD_GOAL_PERCENTAGE": 0.444,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 1,
          "ASSISTS": 0,
          "TURNOVERS": 0,
          "STEALS": 1,
          "BLOCKS": 1
        },
        {
          "DATE": "NOV 02, 2019",
          "MATCHUP": "NOP @ OKC",
          "MINUTES": 27,
          "POINTS": 17,
          "FIELD_GOAL_PERCENTAGE": 0.5,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 3,
          "ASSISTS": 1,
          "TURNOVERS": 0,
          "STEALS": 1,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 31, 2019",
          "MATCHUP": "NOP vs. DEN",
          "MINUTES": 17,
          "POINTS": 7,
          "FIELD_GOAL_PERCENTAGE": 1,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 2,
          "ASSISTS": 2,
          "TURNOVERS": 0,
          "STEALS": 0,
          "BLOCKS": 1
        },
        {
          "DATE": "OCT 28, 2019",
          "MATCHUP": "NOP vs. GSW",
          "MINUTES": 25,
          "POINTS": 5,
          "FIELD_GOAL_PERCENTAGE": 0.1,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 0,
          "ASSISTS": 3,
          "TURNOVERS": 2,
          "STEALS": 0,
          "BLOCKS": 1
        },
        {
          "DATE": "OCT 26, 2019",
          "MATCHUP": "NOP @ HOU",
          "MINUTES": 28,
          "POINTS": 14,
          "FIELD_GOAL_PERCENTAGE": 0.25,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 1,
          "ASSISTS": 1,
          "TURNOVERS": 5,
          "STEALS": 0,
          "BLOCKS": 0
        }
      ]
    },
    {
      "PLAYER_ID": 1627982,
      "NAME": "Josh Gray",
      "JERSEY_NUMBER": "5",
      "POSITION": "G",
      "HEIGHT": "6-0",
      "WEIGHT": "180",
      "BIRTHDAY": "SEP 09, 1993",
      "AGE": 26,
      "EXPERIENCE": "1",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": "N/A",
          "POINTS": "N/A",
          "FIELD_GOAL_PERCENTAGE": "N/A",
          "OFFENSIVE_REBOUNDS": "N/A",
          "DEFENSIVE_REBOUNDS": "N/A",
          "ASSISTS": "N/A",
          "TURNOVERS": "N/A",
          "STEALS": "N/A",
          "BLOCKS": "N/A"
        }
      ]
    },
    {
      "PLAYER_ID": 1626143,
      "NAME": "Jahlil Okafor",
      "JERSEY_NUMBER": "8",
      "POSITION": "C-F",
      "HEIGHT": "6-10",
      "WEIGHT": "270",
      "BIRTHDAY": "DEC 15, 1995",
      "AGE": 23,
      "EXPERIENCE": "4",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": 18.3,
          "POINTS": 9.9,
          "FIELD_GOAL_PERCENTAGE": 0.614,
          "OFFENSIVE_REBOUNDS": 1.9,
          "DEFENSIVE_REBOUNDS": 3.3,
          "ASSISTS": 1.1,
          "TURNOVERS": 1.9,
          "STEALS": 0.4,
          "BLOCKS": 1
        },
        {
          "DATE": "NOV 04, 2019",
          "MATCHUP": "NOP @ BKN",
          "MINUTES": 21,
          "POINTS": 4,
          "FIELD_GOAL_PERCENTAGE": 0.333,
          "OFFENSIVE_REBOUNDS": 2,
          "DEFENSIVE_REBOUNDS": 2,
          "ASSISTS": 1,
          "TURNOVERS": 1,
          "STEALS": 0,
          "BLOCKS": 1
        },
        {
          "DATE": "NOV 02, 2019",
          "MATCHUP": "NOP @ OKC",
          "MINUTES": 29,
          "POINTS": 15,
          "FIELD_GOAL_PERCENTAGE": 0.5,
          "OFFENSIVE_REBOUNDS": 6,
          "DEFENSIVE_REBOUNDS": 6,
          "ASSISTS": 3,
          "TURNOVERS": 4,
          "STEALS": 0,
          "BLOCKS": 2
        },
        {
          "DATE": "OCT 31, 2019",
          "MATCHUP": "NOP vs. DEN",
          "MINUTES": 34,
          "POINTS": 26,
          "FIELD_GOAL_PERCENTAGE": 0.615,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 5,
          "ASSISTS": 1,
          "TURNOVERS": 3,
          "STEALS": 2,
          "BLOCKS": 1
        },
        {
          "DATE": "OCT 28, 2019",
          "MATCHUP": "NOP vs. GSW",
          "MINUTES": 12,
          "POINTS": 6,
          "FIELD_GOAL_PERCENTAGE": 0.75,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 4,
          "ASSISTS": 1,
          "TURNOVERS": 4,
          "STEALS": 1,
          "BLOCKS": 1
        },
        {
          "DATE": "OCT 26, 2019",
          "MATCHUP": "NOP @ HOU",
          "MINUTES": 12,
          "POINTS": 6,
          "FIELD_GOAL_PERCENTAGE": 0.75,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 4,
          "ASSISTS": 2,
          "TURNOVERS": 0,
          "STEALS": 0,
          "BLOCKS": 1
        }
      ]
    },
    {
      "PLAYER_ID": 1629637,
      "NAME": "Jaxson Hayes",
      "JERSEY_NUMBER": "10",
      "POSITION": "C-F",
      "HEIGHT": "6-11",
      "WEIGHT": "220",
      "BIRTHDAY": "MAY 23, 2000",
      "AGE": 19,
      "EXPERIENCE": "R",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": 15.8,
          "POINTS": 7.8,
          "FIELD_GOAL_PERCENTAGE": 0.619,
          "OFFENSIVE_REBOUNDS": 2,
          "DEFENSIVE_REBOUNDS": 1.8,
          "ASSISTS": 1.3,
          "TURNOVERS": 0.8,
          "STEALS": 1,
          "BLOCKS": 0.3
        },
        {
          "DATE": "NOV 04, 2019",
          "MATCHUP": "NOP @ BKN",
          "MINUTES": 16,
          "POINTS": 3,
          "FIELD_GOAL_PERCENTAGE": 0,
          "OFFENSIVE_REBOUNDS": 3,
          "DEFENSIVE_REBOUNDS": 2,
          "ASSISTS": 1,
          "TURNOVERS": 2,
          "STEALS": 2,
          "BLOCKS": 0
        },
        {
          "DATE": "NOV 02, 2019",
          "MATCHUP": "NOP @ OKC",
          "MINUTES": 14,
          "POINTS": 4,
          "FIELD_GOAL_PERCENTAGE": 0.4,
          "OFFENSIVE_REBOUNDS": 4,
          "DEFENSIVE_REBOUNDS": 1,
          "ASSISTS": 3,
          "TURNOVERS": 0,
          "STEALS": 1,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 31, 2019",
          "MATCHUP": "NOP vs. DEN",
          "MINUTES": 9,
          "POINTS": 5,
          "FIELD_GOAL_PERCENTAGE": 1,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 2,
          "ASSISTS": 0,
          "TURNOVERS": 1,
          "STEALS": 0,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 28, 2019",
          "MATCHUP": "NOP vs. GSW",
          "MINUTES": 24,
          "POINTS": 19,
          "FIELD_GOAL_PERCENTAGE": 0.818,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 2,
          "ASSISTS": 1,
          "TURNOVERS": 0,
          "STEALS": 1,
          "BLOCKS": 1
        }
      ]
    },
    {
      "PLAYER_ID": 201950,
      "NAME": "Jrue Holiday",
      "JERSEY_NUMBER": "11",
      "POSITION": "G",
      "HEIGHT": "6-3",
      "WEIGHT": "205",
      "BIRTHDAY": "JUN 12, 1990",
      "AGE": 29,
      "EXPERIENCE": "10",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": 35,
          "POINTS": 14.2,
          "FIELD_GOAL_PERCENTAGE": 0.373,
          "OFFENSIVE_REBOUNDS": 0.8,
          "DEFENSIVE_REBOUNDS": 3.8,
          "ASSISTS": 6,
          "TURNOVERS": 2.2,
          "STEALS": 1.8,
          "BLOCKS": 0.8
        },
        {
          "DATE": "NOV 04, 2019",
          "MATCHUP": "NOP @ BKN",
          "MINUTES": 34,
          "POINTS": 15,
          "FIELD_GOAL_PERCENTAGE": 0.412,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 6,
          "ASSISTS": 3,
          "TURNOVERS": 2,
          "STEALS": 4,
          "BLOCKS": 2
        },
        {
          "DATE": "NOV 02, 2019",
          "MATCHUP": "NOP @ OKC",
          "MINUTES": 35,
          "POINTS": 16,
          "FIELD_GOAL_PERCENTAGE": 0.4,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 3,
          "ASSISTS": 6,
          "TURNOVERS": 2,
          "STEALS": 1,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 31, 2019",
          "MATCHUP": "NOP vs. DEN",
          "MINUTES": 32,
          "POINTS": 19,
          "FIELD_GOAL_PERCENTAGE": 0.412,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 5,
          "ASSISTS": 7,
          "TURNOVERS": 2,
          "STEALS": 2,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 25, 2019",
          "MATCHUP": "NOP vs. DAL",
          "MINUTES": 33,
          "POINTS": 8,
          "FIELD_GOAL_PERCENTAGE": 0.182,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 3,
          "ASSISTS": 8,
          "TURNOVERS": 0,
          "STEALS": 2,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 22, 2019",
          "MATCHUP": "NOP @ TOR",
          "MINUTES": 41,
          "POINTS": 13,
          "FIELD_GOAL_PERCENTAGE": 0.4,
          "OFFENSIVE_REBOUNDS": 2,
          "DEFENSIVE_REBOUNDS": 2,
          "ASSISTS": 6,
          "TURNOVERS": 5,
          "STEALS": 0,
          "BLOCKS": 2
        }
      ]
    },
    {
      "PLAYER_ID": 1627742,
      "NAME": "Brandon Ingram",
      "JERSEY_NUMBER": "14",
      "POSITION": "F",
      "HEIGHT": "6-7",
      "WEIGHT": "190",
      "BIRTHDAY": "SEP 02, 1997",
      "AGE": 22,
      "EXPERIENCE": "3",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": 31.7,
          "POINTS": 25.9,
          "FIELD_GOAL_PERCENTAGE": 0.552,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 6.1,
          "ASSISTS": 4.3,
          "TURNOVERS": 2.6,
          "STEALS": 0.7,
          "BLOCKS": 1
        },
        {
          "DATE": "NOV 04, 2019",
          "MATCHUP": "NOP @ BKN",
          "MINUTES": 37,
          "POINTS": 40,
          "FIELD_GOAL_PERCENTAGE": 0.708,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 5,
          "ASSISTS": 5,
          "TURNOVERS": 4,
          "STEALS": 2,
          "BLOCKS": 0
        },
        {
          "DATE": "NOV 02, 2019",
          "MATCHUP": "NOP @ OKC",
          "MINUTES": 13,
          "POINTS": 7,
          "FIELD_GOAL_PERCENTAGE": 0.6,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 3,
          "ASSISTS": 1,
          "TURNOVERS": 1,
          "STEALS": 0,
          "BLOCKS": 1
        },
        {
          "DATE": "OCT 31, 2019",
          "MATCHUP": "NOP vs. DEN",
          "MINUTES": 36,
          "POINTS": 25,
          "FIELD_GOAL_PERCENTAGE": 0.583,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 3,
          "ASSISTS": 5,
          "TURNOVERS": 3,
          "STEALS": 0,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 28, 2019",
          "MATCHUP": "NOP vs. GSW",
          "MINUTES": 31,
          "POINTS": 27,
          "FIELD_GOAL_PERCENTAGE": 0.435,
          "OFFENSIVE_REBOUNDS": 3,
          "DEFENSIVE_REBOUNDS": 7,
          "ASSISTS": 6,
          "TURNOVERS": 2,
          "STEALS": 2,
          "BLOCKS": 1
        },
        {
          "DATE": "OCT 26, 2019",
          "MATCHUP": "NOP @ HOU",
          "MINUTES": 39,
          "POINTS": 35,
          "FIELD_GOAL_PERCENTAGE": 0.636,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 14,
          "ASSISTS": 5,
          "TURNOVERS": 3,
          "STEALS": 0,
          "BLOCKS": 0
        }
      ]
    },
    {
      "PLAYER_ID": 1628402,
      "NAME": "Frank Jackson",
      "JERSEY_NUMBER": "15",
      "POSITION": "G",
      "HEIGHT": "6-3",
      "WEIGHT": "205",
      "BIRTHDAY": "MAY 04, 1998",
      "AGE": 21,
      "EXPERIENCE": "1",
      "STATS": [
        {
          "DATE": "2019-20",
          "MATCHUP": "Season",
          "MINUTES": 19.4,
          "POINTS": 11.7,
          "FIELD_GOAL_PERCENTAGE": 0.462,
          "OFFENSIVE_REBOUNDS": 0.1,
          "DEFENSIVE_REBOUNDS": 0.9,
          "ASSISTS": 1.6,
          "TURNOVERS": 1.7,
          "STEALS": 0.9,
          "BLOCKS": 0.1
        },
        {
          "DATE": "NOV 04, 2019",
          "MATCHUP": "NOP @ BKN",
          "MINUTES": 25,
          "POINTS": 12,
          "FIELD_GOAL_PERCENTAGE": 0.444,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 0,
          "ASSISTS": 2,
          "TURNOVERS": 5,
          "STEALS": 2,
          "BLOCKS": 0
        },
        {
          "DATE": "NOV 02, 2019",
          "MATCHUP": "NOP @ OKC",
          "MINUTES": 22,
          "POINTS": 12,
          "FIELD_GOAL_PERCENTAGE": 0.364,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 0,
          "ASSISTS": 1,
          "TURNOVERS": 1,
          "STEALS": 0,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 31, 2019",
          "MATCHUP": "NOP vs. DEN",
          "MINUTES": 19,
          "POINTS": 21,
          "FIELD_GOAL_PERCENTAGE": 0.8,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 3,
          "ASSISTS": 0,
          "TURNOVERS": 1,
          "STEALS": 1,
          "BLOCKS": 0
        },
        {
          "DATE": "OCT 28, 2019",
          "MATCHUP": "NOP vs. GSW",
          "MINUTES": 23,
          "POINTS": 9,
          "FIELD_GOAL_PERCENTAGE": 0.364,
          "OFFENSIVE_REBOUNDS": 0,
          "DEFENSIVE_REBOUNDS": 2,
          "ASSISTS": 3,
          "TURNOVERS": 2,
          "STEALS": 2,
          "BLOCKS": 1
        },
        {
          "DATE": "OCT 26, 2019",
          "MATCHUP": "NOP @ HOU",
          "MINUTES": 18,
          "POINTS": 9,
          "FIELD_GOAL_PERCENTAGE": 0.333,
          "OFFENSIVE_REBOUNDS": 1,
          "DEFENSIVE_REBOUNDS": 1,
          "ASSISTS": 2,
          "TURNOVERS": 2,
          "STEALS": 1,
          "BLOCKS": 0
        }
      ]
    },
   ... Rest of json removed due to character limit
  ]
}

通过使用以下代码,我可以删除HOME_ROSTER中本赛季未参加比赛的球员,按平均上场时间排序,并按分钟提取前5名球员。

jq '.["HOME_ROSTER"] | map(select(.STATS[0].MINUTES != "N/A")) | sort_by(.STATS[0].MINUTES) | .[-5:]'

我该如何进行适当的过滤和排序,以便保留JSON的原始结构?我对一般如何使用jq解决此类问题感兴趣。

等效的python是:

import sys
import json


if __name__ == "__main__":
    JSON = json.loads(sys.stdin.read())
    for team in ("HOME", "AWAY"):
        JSON[f"{team}_ROSTER"] = [player for player in JSON[f"{team}_ROSTER"] if player["STATS"][0]["MINUTES"] != "N/A"]
        JSON[f"{team}_ROSTER"] = sorted(JSON[f"{team}_ROSTER"], key = lambda player: player["STATS"][0]["MINUTES"], reverse = True)
        JSON[f"{team}_ROSTER"] = JSON[f"{team}_ROSTER"][0:6]
    print(json.dumps(JSON))

1 个答案:

答案 0 :(得分:2)

  

我对一般如何使用jq解决此类问题感兴趣。

通常,我们的想法是使用|=而不只是使用=,但是有时需要使用括号将其分组。

因此,在您的情况下,解决方案的格式为:

.["HOME_ROSTER"] |= (...)

也就是说,解决方案是:

.["HOME_ROSTER"] |=
  (map(select(.STATS[0].MINUTES != "N/A"))
   | sort_by(.STATS[0].MINUTES) | .[-5:] )