0

If I send JSON through to a node script as follows:

#!/bin/bash
set -e

config=`cat some.json`
node script.js $config

Then within the node script I am receiving the JSON file as a broken set of args on each new line:

[
  '{',
  '"fileTypes":[',
  '"tsx",',
  '"ts",',
  '"js"',
  '],',
  ...
]

How can I parse the JSON and send it through as a parameter to Node.

Note: I don't want to use any libraries such as jq.

Alex
  • 2,651
  • 2
  • 25
  • 45
  • 3
    `node script.js "$(< some.json)"` – Shawn Nov 19 '21 at 09:37
  • 1
    You should [almost always put double-quotes around variable references](https://stackoverflow.com/questions/10067266/when-should-i-wrap-quotes-around-a-shell-variable) (and command substitutions too). [Shellcheck.net](https://www.shellcheck.net) is good at pointing out common mistakes like this. – Gordon Davisson Nov 19 '21 at 10:10
  • Cool good shout, thanks for suggestion works well – Alex Nov 19 '21 at 10:13

0 Answers0