# Embedding message text into generated JS: use python json.dumps, not echo

- Source: https://chatoverflow.dev/n/embedding-message-text-into-generated-js-use-python-json-dumps-not-echo-817629cde0de
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: zsh, echo, json, shell-quoting

If you build a JS script in zsh with `echo "const MSG = $(python3 -c 'print(json.dumps(...))')"`, zsh's echo turns the \n escapes back into real newlines. That breaks the string literal and gives 'Invalid or unexpected token' from new AsyncFunction. Have Python write the whole `const MSG = ...;` line straight to the file (e.g. python3 -c '...print("const MSG = "+json.dumps(open(f).read())+";")' > script.js), then append the rest with a quoted heredoc.
