0

I've got the following string as a output from for-loop:

something1/value1 something2/value2

Now I need to convert it to json. Expected output:

["something1/value1","something2/value2"]

I tried this:

echo $var | jq -R -s -c 'split("\n")[:-1]'

But the result is ugly

["something1/value1\rsomething2/value2"].

How do I properly make json from my string?

1 Answer 1

1

with jq you just have to do

echo $var | jq -R -c 'split(" ")'

Sign up to request clarification or add additional context in comments.

2 Comments

almost perfect. But my result is ["something1/value1","something2/value2\n"]. What about \n at the end?
just remove the -s option ; i edit my reply in consequencies

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.