C
C
copyerfiled2016-10-14 23:30:39
API
copyerfiled, 2016-10-14 23:30:39

How to cram a variable containing information into several lines in JSON?

There is a BASH script in which CURL sends data in JSON format to a certain API using the POST method.
The $1 variable comes into the script from the outside, containing various information, including various symbols, and the whole thing is in a few lines.
In general, the value of the variable needs to be transferred to another variable, as I understand it, with escaping strings and special characters, that is, everything in one line and so that the quotes, commas and colons there are not perceived by the JSON format as their own.
How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
copyerfiled, 2016-10-15
@copyerfiled

In general, I scouted what needs to be done, but I still do not understand how.
It is necessary to replace the
/n/r metacharacters
with
\u003cbr /\u003e\r\n
in such a way that this construction is perceived as text.
As I understand it, we take the arriving variable $1, apply something to it, and shove it into $test.
echo $1
Here is the text of the first line
Here is the text of the second line.
Something like this:
test=$(echo $1 | metasymbol changer )
It should end up like this:
echo $test
Here is the text of the first line\u003cbr /\u003e\r\nHere is the text of the second line.
What can be used for these purposes? (Maybe there tr, sed, awk, grep?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question