>_ IzzyLab

Hands-on task

This task is step 10 of the course “JSON, YAML and XML in the terminal”

jq: to_entries into key=value pairs

medium~5 min

/root/conf.json holds a flat object with connection settings (strings, numbers, booleans). Convert it into lines of the form key=value (one per key) and write them to /root/conf.env — like in a .env file.

What you'll practise:
  • jq
  • to_entries
  • interpolation
  • -r
  • object to pairs

Topic breakdown

to_entries turns an object {k: v, …} into an array of pairs [{"key":k,"value":v}, …] that is easy to iterate over (the inverse is from_entries). This is the key technique when you need to treat field names as data: rename keys, filter by key, assemble a different format. String interpolation "\(expression)" substitutes values into a string, and the -r flag prints the result without JSON quotes — together they turn JSON into plain-text formats like .env or CSV.

What's checked

  1. key=value pairs

What it looks like