↑ ↓ select, Enter open, Esc close

Extract a single field from JSON with jq

Adjust the values, the command updates live
user@server
jq -r '.require.php' composer.json

Prints the value at the given path. Nested fields are joined with dots, array elements are accessed with .[0]. The -r option returns strings without quotes, so the result can be used directly in scripts. If the field does not exist, jq prints null.

Note: The filter '.require | keys[]' lists all keys of an object.

Also searched as

  • get value from json command line
  • jq raw output into shell variable
  • query nested json field jq

Related one-liners

All in Text processing

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.