I want to add \t before each element in the resulting jq array and this is for formatting purposes as the result will get added to a file. here is the json file:
{
"array": ["element1", "element2"]
}
When you read this array with jq content=$(jq '.array' file) and echo "$content" we get:
[
"element1",
"element2"
]
What I want to have this:
[
\t\t"element1",
\t\t"element2"
\t\t]
What is the best way to do this?
\t\t? Are you adding this array to another JSON file? If so, it would be better to do that withjqdirectly rather than via somesedprocessing.\andt, or a literal tab character. Also, you seem to have accepted an answer, even though this generates output that is not like that in the question (the tabs are at the start of the line rather than at the start of each element). Since you mentioned "before each element" rather than "at the start of the line", I thought this was an important distinction to make.\,t,\,tor 2 literal tab characters inserted. Inserting\t\tis not the same as inserting 2 tab chars,\tis an escape sequence that some tools will use in output statements to generate tab chars but that doesn't mean\tis a tab char, and at no point do you say in your question that you want tab characters but instead show literal\ts in your expected output. If you're going to show that then at least say "those\ts are literal tab chars" or similar in your question.