skip to content
Alvin Lucillo

Encoding file into string

/ 1 min read

💻 Tech

To get the file contents into a string and ensure that new lines are escaped, use jq: jq -Rs . < test.html

test.html

<html>
	<body>
		<h1>Hello, World!</h1>
	</body>
</html>

Terminal

jq -Rs . < test.html
"<html>\n  <body>\n    <h1>Hello, World!</h1>\n  </body>\n</html>\n"