>_ IzzyLab

Hands-on task

This task is step 9 of the course “curl and HTTP APIs”

Extract a field from a JSON response

medium~5 min

The server serves JSON at http://localhost/api.json. Fetch it, extract the value of the user field, and write only that value to /root/user.txt.

In the Site tab, open the /api.json link — the browser shows the whole JSON, but you need just one field.

What you'll practise:
  • curl
  • jq
  • json
  • pipeline
  • parsing

Topic breakdown

Parsing JSON in the shell is built on a pipeline: one tool (curl) fetches the data, another (jq) parses it by structure. In jq a path to a top-level field is written with a dot, and by default string values are printed in quotes — for the "raw" value without quotes there is a separate option. This is the basic pattern for extracting a single field from an API response.

What's checked

  1. user field extracted

What it looks like