I'm trying to write a small script to upload snippets of code to a service provider we use that requires you to pass that code inside a JSON object.
file_content=$(<my_file.js)
curl -X POST -H "Content-Type: application/json"
-d '{"name":$file_name","script":"$file_content"}' https://someservice.com/api/endpoint
Where file_content is the javascript code inside my_file. The problem is that printed just like that, the payload is invalid. I'm trying to find a way to read that file in a way that it's valid json. I know it's rather specific but wondering if such command exists.
EDIT: Another option would be to just place the entire JSON object in a file, but i would like to avoid that if possible.