Practice the basics of jq using Pokemon data
Practice the basics of jq using Pokemon data Data Science Project
Data Science Tools

Practice the basics of jq using Pokemon data

jq is an amazing command line tool to process and analyze JSON files with a declarative format. In this project, you'll practice the basics of jq and JSON analysis using a dataset containing Pokemon.
Start this project
Practice the basics of jq using Pokemon dataPractice the basics of jq using Pokemon data
Project Created by

Ishan Das Sharma

Project Activities

All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.

All our activities include solutions with explanations on how they work and why we chose them.

codevalidated

Write the expression to select the 100th Pokemon

What's the jq expression used to select the 100th pokemon? Enter it below (remember to enter the full expression, including jq and pokemon.json):

codevalidated

Select only the `Name`, `Type 1` and `Total` from the 255th pokemon

Write the expression to select values individually, your output should look something like:

"Torchic"
"Fire"
310
codevalidated

Select `Name`, `Type 1`, and `Total` as an object

Now we want to select the same values as before, but this time we want jq to return an object. Your expression should look like:

{
  "Name": "Torchic",
  "Type 1": "Fire",
  "Total": 310
}
codevalidated

Write an expression to select the last 3 Pokémon

Write a slicing expression to select the last 3 pokemon.

Your output should look something like:

[
  {
    "Name": "Diancie",
    "Type 1": "Rock",
    "Type 2": "Fairy",
    "Total": 600,
    "HP": 50,
    "Attack": 100,
    "Defense": 150,
    "Sp. Atk": 100,
    "Sp. Def": 150,
    "Speed": 50,
    "Generation": 6,
    "Legendary": true
  }
  ...
]
codevalidated

Write an expression to find the total number of Pokemon

codevalidated

Write an expression to select the maximum value of `Total`

codevalidated

Write an expression to find the average value of `Total`

codevalidated

Select the Pokémon that have an `Attack` greater than 150

Your output should look something like:

{
  "Name": "Slaking",
  "Type 1": "Normal",
  "Type 2": null,
  "Total": 670,
  "HP": 150,
  "Attack": 160,
  "Defense": 100,
  "Sp. Atk": 95,
  "Sp. Def": 65,
  "Speed": 100,
  "Generation": 3,
  "Legendary": false
}
{
  "Name": "Rampardos",
  "Type 1": "Rock",
  "Type 2": null,
  "Total": 495,
  "HP": 97,
  "Attack": 165,
  "Defense": 60,
  "Sp. Atk": 65,
  "Sp. Def": 50,
  "Speed": 58,
  "Generation": 4,
  "Legendary": false
}
...
codevalidated

Select only the `Name` and `Total` properties from Pokémon that have a `Total` greater than 650

Your output should look something like:

[
  {
    "Name": "Mewtwo",
    "Total": 680
  },
  {
    "Name": "Lugia",
    "Total": 680
  },
  {
    "Name": "Ho-oh",
    "Total": 680
  },
  {
    "Name": "Slaking",
    "Total": 670
  },
  ...
]
codevalidated

Select all the Pokémon that have a `Type 2` value set

That is, Type 2 is not null. Limit your results to the first 5 results.

Your output should look something like:

[
  {
    "Name": "Bulbasaur",
    "Type 1": "Grass",
    "Type 2": "Poison",
    "Total": 318,
    "HP": 45,
    "Attack": 49,
    "Defense": 49,
    "Sp. Atk": 65,
    "Sp. Def": 65,
    "Speed": 45,
    "Generation": 1,
    "Legendary": false
  },
  {
    "Name": "Ivysaur",
    "Type 1": "Grass",
    "Type 2": "Poison",
    "Total": 405,
    "HP": 60,
    "Attack": 62,
    "Defense": 63,
    "Sp. Atk": 80,
    "Sp. Def": 80,
    "Speed": 60,
    "Generation": 1,
    "Legendary": false
  },
  ...
]
codevalidated

Select the names of all the Legendary Pokemon

Your output should look something like:

[
  "Articuno",
  "Zapdos",
  "Moltres",
  "Mewtwo",
  "Raikou",
  "Entei",
  "Suicune",
  "Lugia",
  "Ho-oh",
  ...
]
codevalidated

Extract the names of all dual-type (having both Type 1 and Type 2 Pokemon)

Your output should look something like:

[
  "Bulbasaur",
  "Ivysaur",
  "Venusaur",
  "Charizard",
  "Butterfree",
  "Weedle",
  "Kakuna",
  "Beedrill",
  "Pidgey",
  ...
]
codevalidated

Extract the names of all Poison-type Pokemon.

It should include Pokémon having Poison as either their Type 1 or as their Type 2.

Your output should look something like:

{
  "Name": "Bulbasaur",
  "Type 1": "Grass",
  "Type 2": "Poison",
  "Total": 318,
  "HP": 45,
  "Attack": 49,
  "Defense": 49,
  "Sp. Atk": 65,
  "Sp. Def": 65,
  "Speed": 45,
  "Generation": 1,
  "Legendary": false
}
{
  "Name": "Ivysaur",
  "Type 1": "Grass",
  "Type 2": "Poison",
  "Total": 405,
  "HP": 60,
  "Attack": 62,
  "Defense": 63,
  "Sp. Atk": 80,
  "Sp. Def": 80,
  "Speed": 60,
  "Generation": 1,
  "Legendary": false
}
..
...
{
  "Name": "Dragalge",
  "Type 1": "Poison",
  "Type 2": "Dragon",
  "Total": 494,
  "HP": 65,
  "Attack": 75,
  "Defense": 90,
  "Sp. Atk": 97,
  "Sp. Def": 123,
  "Speed": 44,
  "Generation": 6,
  "Legendary": false
}
codevalidated

Calculate the average Defense of non-Legendary Pokemon

Combining above concepts + Statistical methods

codevalidated

Find the Pokémon with an `HP` greater than 70, sorted by HP in Ascending mode

Your output should look something like:

[
  {
    "Name": "Purugly",
    "Type 1": "Normal",
    "Type 2": null,
    "Total": 452,
    "HP": 71,
    "Attack": 82,
    "Defense": 64,
    "Sp. Atk": 64,
    "Sp. Def": 59,
    "Speed": 112,
    "Generation": 4,
    "Legendary": false
  },
  {
    "Name": "Vanilluxe",
    "Type 1": "Ice",
    "Type 2": null,
    "Total": 535,
    "HP": 71,
    "Attack": 95,
    "Defense": 85,
    "Sp. Atk": 110,
    "Sp. Def": 95,
    "Speed": 79,
    "Generation": 5,
    "Legendary": false
  },
  ...
]
codevalidated

Find the Pokémon with a `Defense` value greater than 100, sorted by `Defense` in descending mode

Your output should look something like:

[
  {
    "Name": "Shuckle",
    "Type 1": "Bug",
    "Type 2": "Rock",
    "Total": 505,
    "HP": 20,
    "Attack": 10,
    "Defense": 230,
    "Sp. Atk": 10,
    "Sp. Def": 230,
    "Speed": 5,
    "Generation": 2,
    "Legendary": false
  },
  {
    "Name": "Regirock",
    "Type 1": "Rock",
    "Type 2": null,
    "Total": 580,
    "HP": 80,
    "Attack": 100,
    "Defense": 200,
    "Sp. Atk": 50,
    "Sp. Def": 100,
    "Speed": 50,
    "Generation": 3,
    "Legendary": true
  },
  ...
]

codevalidated

Identify the Pokémon with the highest Attack in Generation 2

Your output should look something like:

{
  "Name": "Tyranitar",
  "Type 1": "Rock",
  "Type 2": "Dark",
  "Total": 600,
  "HP": 100,
  "Attack": 134,
  "Defense": 110,
  "Sp. Atk": 95,
  "Sp. Def": 100,
  "Speed": 61,
  "Generation": 2,
  "Legendary": false
}
codevalidated

Find all Defensive Pokémon (having more Defense than Attack)

Your output should look something like:

[
  ....

  {
    "Name": "Volcanion",
    "Type 1": "Fire",
    "Type 2": "Water",
    "Total": 600,
    "HP": 80,
    "Attack": 110,
    "Defense": 120,
    "Sp. Atk": 130,
    "Sp. Def": 90,
    "Speed": 70,
    "Generation": 6,
    "Legendary": true
  }
]
codevalidated

Group the Pokémon by their primary type (Type 1).

Your output should look something like:

[
  [
    ...
    {
      "Name": "Clauncher",
      "Type 1": "Water",
      "Type 2": null,
      "Total": 330,
      "HP": 50,
      "Attack": 53,
      "Defense": 62,
      "Sp. Atk": 58,
      "Sp. Def": 63,
      "Speed": 44,
      "Generation": 6,
      "Legendary": false
    },
    {
      "Name": "Clawitzer",
      "Type 1": "Water",
      "Type 2": null,
      "Total": 500,
      "HP": 71,
      "Attack": 73,
      "Defense": 88,
      "Sp. Atk": 120,
      "Sp. Def": 89,
      "Speed": 59,
      "Generation": 6,
      "Legendary": false
    }
  ]
]
codevalidated

Get the number of Pokémon by Generation

Your output should look something like:

{
  "1": 1,
  "2": 1,
  "3": 1,
  "4": 1,
  "5": 1,
  "6": 7
}
codevalidated

Get average HP by Type 1

Your output should look something like:

{
  "Bug": 55.95238095238095,
  "Dark": 67.17857142857143,
  "Dragon": 78.04166666666667,
  "Electric": 59.5,
  "Fairy": 74.11764705882354,
  "Fighting": 70.24,
  "Fire": 68.59574468085107,
  "Flying": 68,
  "Ghost": 61.56521739130435,
  "Grass": 66.1969696969697,
  "Ground": 72.4,
  "Ice": 71.65217391304348,
  "Normal": 76.52688172043011,
  "Poison": 67.25,
  "Psychic": 70.61702127659575,
  "Rock": 64.53658536585365,
  "Steel": 64.81818181818181,
  "Water": 70.86666666666666
}
codevalidated

Use `reduce` to calculate how many Pokémon are legendary?

Practice the basics of jq using Pokemon dataPractice the basics of jq using Pokemon data
Project Created by

Ishan Das Sharma

This project is part of

Data Science Tools

Explore other projects