I need to catch a mistake when lifting a service. The answer may be null , a string error message like
error services-migration/foobar: Not found: services-migration/foobar
or valid JSON when everything is ok. I was wondering if there is a jq way to just check if the provided string is valid JSON. I could check the string for some keywords, such as error fe, but I am looking for a more reliable option, for example, for example. I get true/false or 1/0 from jq. I was looking through jq as well as some questions here about SO, but it was all about finding and displaying key values ββfrom JSON, but nothing related to just checking the string.
UPDATE:
I have it:
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 in else .
source share