在Shell命令(而不是JSON文件)中写入JSON时出错

时间:2019-05-10 08:35:34

标签: node.js json shell

我正在节点中运行以下shell脚本

     cp.exec(`freshdesk --config config_tap.json
     | node main/src/model/addAccountId.js | 
     target-postgres --config config_target.json`)

这很好用,但是配置文件必须是动态的,所以我将config_tap.json和config_target.json更改为以下内容

config_tap.json

     --config <(echo '{ "api_key": "${key}", "domain": "${domain}", 
     "start_date": "2017-01-17T20:32:05Z"}')

config_target.json

     --config <(echo '{ "postgres_host": "${process.env.PGHOST}", 
     "postgres_port": "${process.env.PGPORT}", "postgres_database": 
     "${process.env.PGDATABASE}", "postgres_username": 
     "${process.env.PGUSER}", "postgres_password": 
     "${process.env.PGPASSWORD}", "postgres_schema": "freshdesk" }')

这适用于config_tap.json,但不适用于config_target.json。我收到以下错误

     json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

config_target.json文件

     {
       "postgres_host": "host",
       "postgres_port": "5432",
       "postgres_database": "db",
       "postgres_username": "user",
       "postgres_password": "passwd",
       "postgres_schema": "freshdesk"
     }

我试图用printf改变回声,但是没有解决。 我也尝试在JSON文件中输入新行,但也没有解决。 我在做什么错了?

这很奇怪,他接受了连接,然后给出了错误

INFO PostgresTarget created with established connection: `host=host port=5432 dbname=db user=user`, PostgreSQL schema: `freshdesk`
Traceback (most recent call last):
  File "/home/dylan/.virtualenvs/target-postgres/bin/target-postgres", line 11, in <module>
    sys.exit(cli())
  File "/home/dylan/.virtualenvs/target-postgres/lib/python3.6/site-packages/target_postgres/__init__.py", line 36, in cli
    main(args.config)
  File "/home/dylan/.virtualenvs/target-postgres/lib/python3.6/site-packages/target_postgres/__init__.py", line 30, in main
    target_tools.main(postgres_target)
  File "/home/dylan/.virtualenvs/target-postgres/lib/python3.6/site-packages/target_postgres/target_tools.py", line 23, in main
    config = utils.parse_args([]).config
  File "/home/dylan/.virtualenvs/target-postgres/lib/python3.6/site-packages/singer/utils.py", line 168, in parse_args
    args.config = load_json(args.config)
  File "/home/dylan/.virtualenvs/target-postgres/lib/python3.6/site-packages/singer/utils.py", line 109, in load_json
    return json.load(fil)
  File "/usr/lib/python3.6/json/__init__.py", line 299, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

0 个答案:

没有答案