0

How can I convert a multiline variable with special characters into a JSON string using JQ?

$ echo $FPR_LOW
4 issues of 4 matched search query.

Issue counts by category:

 J2EE Bad Practices: Leftover Debug Code => 1 Issues
     ApiApplication.java:23 (Structural)
 Poor Error Handling: Overly Broad Throws => 3 Issues
     controller/BanksController.java:27 (Structural)
     controller/BanksController.java:40 (Structural)
     controller/BanksController.java:51 (Structural)

The above string variable should be a single JSON string.

1

1 Answer 1

2

Pass the value as a jq variable (and tell it not to expect input):

jq -n --arg fpr "$FPR_LOW" '$fpr'
Sign up to request clarification or add additional context in comments.

Comments

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.