Skip to content

Instantly share code, notes, and snippets.

@jameswomack
Created May 13, 2026 12:22
Show Gist options
  • Select an option

  • Save jameswomack/07998edf41c3bae5a061f1c7d22894d2 to your computer and use it in GitHub Desktop.

Select an option

Save jameswomack/07998edf41c3bae5a061f1c7d22894d2 to your computer and use it in GitHub Desktop.
node.js cli pipe output of jq to node -e execute

EXAMPLE

Example

curl -s -X POST 'http://localhost:11000/api/projections/ai-search' -H 'Content-Type: application/json' -d '{"query":"retractable roof stadiums"}' | jq '.data[0]' | node -e '

let input = "";

process.stdin.on("data", chunk => input += chunk);

process.stdin.on("end", () => {

  const parsed = JSON.parse(input);

  const reductionSauce = Object.keys(parsed).reduce((acc, k) => {
    const inty = parseInt(parsed[k]);
    const val = parsed[k].toLocaleString();
    const isInty = inty == val && parsed[k] <= 999;
    acc[k] = k == "parkFactor" ? parsed[k] : (isInty ? parsed[k] : val);
    acc[k] = k.match(/^[a-z]+At$/) ? new Date(parsed[k]) : acc[k];
    console.log(val);
    return acc;
  }, {})

  console.log(`[REDUCE_THE_BOOSE] reductionSauce ${JSON.stringify(reductionSauce)}`);

  console.dir(reductionSauce);

});

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