【问题标题】:Convert mutliline shell variable to JSON string将 mutliline shell 变量转换为 JSON 字符串
【发布时间】:2021-09-25 14:25:56
【问题描述】:

如何使用 JQ 将带有特殊字符的多行变量转换为 JSON 字符串?

$ 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)

上述字符串变量应该是单个 JSON 字符串。

【问题讨论】:

标签: shell jq


【解决方案1】:

将值作为jq 变量传递(并告诉它不要期望输入):

jq -n --arg fpr "$FPR_LOW" '$fpr'

【讨论】:

    猜你喜欢
    • 2020-11-26
    • 1970-01-01
    • 1970-01-01
    • 2012-05-21
    • 2018-02-08
    • 1970-01-01
    • 2010-09-30
    相关资源
    最近更新 更多