[英]Unable to parse json output of artifactory with jq in linux
After executing this query in Artifactory 在Artifactory中执行此查询后
/usr/bin/jfrog rt s foo/01_Develop/01_CI/HPCC-Package-*.zip
I have this output: 我有这个输出:
[Info] Searching artifacts...
[Info] Found 3 artifacts.
[
{
"path": "foo/01_Develop/01_CI/HPCC-Package-47.zip"
},
{
"path": "foo/01_Develop/01_CI/HPCC-Package-48.zip"
},
{
"path": "foo/01_Develop/01_CI/HPCC-Package-72.zip"
}
]
I want to get the last path in json array with this command as suggested here : 我想在JSON数组使用此命令的最后一条路径的建议在这里 :
/usr/bin/jfrog rt s foo/01_Develop/01_CI/HPCC-Package-*.zip | jq .[-1].path
But fails with 但是失败了
parse error: Invalid numeric literal at line 1, column 6
解析错误:第1行第6列的数字常量无效
I cannot change json as it is the output from artifactory jfrog tool 我无法更改json,因为它是人工jfrog工具的输出
NOTE: I have jq version 1.5 注意:我有jq版本1.5
UPDATE: 更新:
Using quotes I have the exact same error: 使用引号我有完全相同的错误:
/usr/bin/jfrog rt s foo/01_Develop/01_CI/HPCC-Package-*.zip | jq '.[-1].path'
/usr/bin/jfrog rt s foo/01_Develop/01_CI/HPCC-Package-*.zip | jq ".[-1].path"
As mentioned in previous answers, this error occurred because the output of JFrog CLI is not pure JSON. 如先前的答案所述,发生此错误是因为JFrog CLI的输出不是纯JSON。
You may want to set the JFROG_CLI_LOG_LEVEL environment variable to ERROR, so that additional messages will not be prompted by the command. 您可能需要将JFROG_CLI_LOG_LEVEL环境变量设置为ERROR,以便该命令不会提示其他消息。
For more details you can read JFrog CLI wiki. 有关更多详细信息,您可以阅读JFrog CLI Wiki。
Your Artifactory output isn't pure json... you need to remove those non-json parts. 您的Artifactory输出不是纯json ...您需要删除那些非json部分。 Assuming we will only need to skip the first two lines, we could just use tail to skip em.
假设我们只需要跳过前两行,就可以使用tail来跳过em。
/usr/bin/jfrog rt s foo/01_Develop/01_CI/HPCC-Package-*.zip | tail -n +3 | jq '.[-1].path'
For the record, here's a jq-only solution that assumes there are exactly two lines of non-JSON prolog: 作为记录,这是一个仅jq的解决方案,该解决方案假定存在两行非JSON序言:
... | jq -n -R -r '[inputs][2:] | join("") | fromjson[-1]'
{
"path": "foo/01_Develop/01_CI/HPCC-Package-72.zip"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.