Skip to content

Instantly share code, notes, and snippets.

@kgust
Last active October 12, 2023 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgust/2e64ed67151159a035c2 to your computer and use it in GitHub Desktop.
Save kgust/2e64ed67151159a035c2 to your computer and use it in GitHub Desktop.
Using jq to parse composer.lock
<composer.lock jq '.packages[] | [.name, .version]' | less
@LeoniePhiline
Copy link

Thanks :)

Using it with a low-effort sd pipeline to produce CSV that can be copy-pasted into a spreadsheet:

<composer.lock jq '.packages[] | [.name, .version]' | sd '(?:\[|\])\n' '' | sd '^  ' '' | sd '(",)\n' '$1 ' > composer.lock.csv

Outputs a CSV list in the shape of:

"brick/math", "0.11.0"
"clue/stream-filter", "v1.6.0"
"cmdisp/monolog-microsoft-teams", "1.2.0"
"dflydev/dot-access-data", "v3.0.2"
"doctrine/cache", "2.2.0"
"doctrine/dbal", "3.6.0"
"doctrine/deprecations", "v1.0.0"
"doctrine/event-manager", "2.0.0"
"doctrine/inflector", "2.0.6"
"doctrine/lexer", "3.0.0"
"dragonmantank/cron-expression", "v3.3.2"
"egulias/email-validator", "4.0.1"
"fruitcake/php-cors", "v1.2.0"
"graham-campbell/result-type", "v1.1.0"
"guzzlehttp/guzzle", "7.5.0"
"guzzlehttp/promises", "1.5.2"
"guzzlehttp/psr7", "2.4.3"
...

@BrianHenryIE
Copy link

Get all information for one package:

jq '."packages-dev"[] | select(.name=="10up/wp_mock")' composer.lock

Get current installed version for one package:

jq '."packages-dev"[] | select(.name=="johnpbloch/wordpress") | .version' composer.lock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment