Luk*_*kas 2 bash shell parsing json jq
我正在使用 JQ 来呈现一些 JSON。一切都很好,但我需要的是没有键引号的输出。尝试使用原始选项,但这根本没有帮助。
剧本:
jq --raw-output --arg ID "$ID" '[.articles[] | { ...
输出:
[
{
"id": "20191022203822",
"title": "How tech companies measure “legal”",
Run Code Online (Sandbox Code Playgroud)
我需要的是:
[
{
id: "20191022203822",
title: "How tech companies measure “legal”",
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
根据 OP 的要求,将我的评论添加到答案中:
每个符合 JSON 的实用程序都会按照 JSON 语法输出整个 JSON,而您想要的是非 JSON 输出。我想你最好的办法是sed在你从标签中删除引号的地方运行它(但这种方法容易出现误报):
jq ... | sed -E 's/(^ *)"([^"]*)":/\1\2:/'
Run Code Online (Sandbox Code Playgroud)
(注意,我将+正则表达式量词更改为*普遍匹配空标签和零缩进)
| 归档时间: |
|
| 查看次数: |
2360 次 |
| 最近记录: |