I need to catch an error when lifting a service. The response can be null
, a string error message like
error services-migration/foobar: Not found: services-migration/foobar
或者在一切正常时使用有效的JSON.我想知道是否有办法用jq
来简单地判断所提供的字符串是否是有效的JSON.我可以用ofc判断字符串中的一些关键字,比如error
f.e.,但我正在寻找一个更可靠的选项,例如,我从jq那里得到了true/false
或1/0
.
更新:
我有这个:
result=$(some command)
from which the result is the string error services-migration/foobar: Not found: services-migration/foobar
And then the if statement:
if jq -e . >/dev/null 2>&1 <<<"$result"; then
echo "it catches it"
else
echo "it doesn't catch it"
fi
And it always ends up in the else
clause.