Skip to content
Discussion options

You must be logged in to vote

Had to try using streamed input and it somewhat works except for the last entry that ends up one line too far, not really sure why but it seems line number if counted from "last" part of the value somehow, which probably also hints on that a package.json with lots of whitespace might cause weird line numbers also,

$ jq --stream -n '[inputs | select((.[0] | .[0] == "scripts" and length > 1) and .[1]) as [[$_,$key], $script] | {$key, value: {$script, line: input_line_number}}] | from_entries' package.json
{
  "preinstall": {
    "script": "npx only-allow pnpm",
    "line": 21
  },
  "postinstall": {
    "script": "simple-git-hooks",
    "line": 22
  },
  "format": {
    "script": "prettier …

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@drowning-cat
Comment options

Comment options

You must be logged in to vote
3 replies
@drowning-cat
Comment options

@drowning-cat
Comment options

@wader
Comment options

Answer selected by drowning-cat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants