Yes, JQ can do all that. Here is how I'd write it:

jq -nr '
def valid_key: test("^[A-Za-z_][0-9A-Za-z_]*$");
def valid_value:
    type != "array" and type != "object" and (
        type != "string" or (test("\u0000") | not)
    );
def valid_input:
    type == "object" and (
        to_entries | all(
            (.key | valid_key) and (.value | valid_value)
        )
    );
input |
    if valid_input and isempty(inputs) then
        to_entries[] | "\(.key)=\(.value | @sh)"
    else
        "bad input\n" | halt_error(1)
    end'
Answer from oguz ismail on Stack Overflow
🌐
GitHub
github.com › jqlang › jq › issues › 1637
is it possible to use jq purely to tell me if the input file is valid or not? · Issue #1637 · jqlang/jq
March 28, 2018 - I have a pretty specific usecase, but I think it would be valuable for the tool itself. I want to know if it's possible to do something like this. $ cat file.json | jq --validate # output message or only output on error. I think the abil...
Author   davidawad
🌐
Medium
pavolkutaj.medium.com › how-to-check-the-validity-of-json-with-jq-in-bash-scripts-21523418f67d
How To Check the Validity of JSON with jq in bash scripts | by Pavol Z. Kutaj | Medium
February 21, 2024 - json_data='{"key": "value", "invalid_key": "missing_quote"}' set +e retval=$(jq -re '""' <<<"${json_data}" 2>&1) if [ -z "${retval}" ]; then echo "JSON parsing successful" else echo "ERROR: jq - ${retval}" fi # >>> ERROR: jq - jq: parse error: Unfinished string at EOF at line 2, column 0
🌐
jq
jqlang.org › manual
jq 1.8 Manual
Remaining arguments are positional JSON text arguments. These are available to the jq program as $ARGS.positional[]. ... Sets the exit status of jq to 0 if the last output value was neither false nor null, 1 if the last output value was either false or null, or 4 if no valid result was ever produced.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-transform-json-data-with-jq
How To Transform JSON Data with jq | DigitalOcean
September 23, 2025 - You can use the identity operator to test whether your setup works. If you see any parse errors, check that seaCreatures.json contains valid JSON. Apply the identity operator to the JSON file with the following command: ... When using jq with files, you always pass a filter followed by the ...
Find elsewhere
🌐
JSONLint
jsonlint.com
JSONLint - The JSON Validator
The best way to find and correct errors while simultaneously saving time is to use an online tool such as JSONLint. JSONLint will check the validity of your JSON code, detect and point out line numbers of the code containing errors.
🌐
Baeldung
baeldung.com › home › web › guide to linux jq command for json processing
Guide to Linux jq Command for JSON Processing | Baeldung on Linux
August 31, 2025 - First, we looked at some of the essential filters jq offers and how they can be used as the building blocks for more complex operations. Then we saw how to use a number of built-in functions that come bundled with jq. We concluded with a complex example showing how to transform one JSON document into another.
🌐
Codeinthehole
til.codeinthehole.com › posts › how-to-use-jq-to-only-parse-valid-json-lines
TIL How to use 'jq' to only parse valid JSON lines — David Winterbottom
August 10, 2023 - $ cat example.txt | jq -R '. as $line | try (fromjson) catch $line' "This is plain text" { "message": "This is JSON" }
🌐
Eliatra
eliatra.com › home › blog › json processing for the command line with jq
JSON Processing for the Command Line with jq
November 10, 2022 - JQ, “a lightweight and flexible command-line JSON processor” · Bats, “a TAP-compliant testing framework for Bash” · A typical test sends curl requests to the Docker environment and then uses jq to validate the JSON result from OpenSearch.
🌐
Nuggets of Wisdom
bernicecpz.hashnode.dev › how-to-verify-keys-in-json-using-jq
Verify JSON Keys with jq
September 2, 2024 - Learn how to verify key existence in JSON using `jq` with methods like `empty`, alternative operator, and `has()` function
Top answer
1 of 2
2

I'm not really familiar with jq in particular, nevertheless, I hope this answer will be useful.

Writing a parser (which parses a file according to a fixed grammar) is generally a complicated and painful task.

Writing a parser that can correct mistakes is on a whole another level. I can't even imagine how complex it could be!

Think about the different ways the input you've shown could be "corrected".

Maybe that [2023.06.07-21.58.47] was meant to have , instead of . and -, that is, the array of six items [2023,06,07,21,58,47]... but then what to do with the rest?

Maybe the whole [2023.06.07-21.58.47] StatManagerLog: is meant to be dropped? Then the file is not a single JSON but a couple of JSON files concatenated; something that jq seems to be able to cope with.

Maybe it's meant to be "[2023.06.07-21.58.47] StatManagerLog":, i.e. the double quotes are missing around the key, and a big outer { } pair encapsulating the entire file is missing too.

I'm sure there are also a few other possibilities where fixes of about this size could make the file a valid JSON. The parser would have no idea which one to choose.

This is similar to spoken languages. Think of how many times you don't clearly hear the entire sentence and ask back because your brain couldn't automatically correct the unheard part... possibly because you can imagine more than 1 way of correcting the sentence and they would result in different meaning.

Long story short: Only you know how exactly the data needs to be fixed, what the original intent was; the parser has no chance of figuring it out. Fix it using some text processing tools (sed, awk, cut, etc.) before feeding it to jq. Or fix whoever emits this data to emit proper JSON.

2 of 2
2

Pre-processing the file by simply replacing each line that starts with [ with a { would make it valid JSON, or at least concatenation of valid JSONs which jq is also able to handle:

$ sed 's/^\[.*/{/' file | jq -c .
{"RoundState":{"State":"Starting","Timestamp":"2023.06.07-21.58.47"}}
{"RoundState":{"State":"StandBy","Timestamp":"2023.06.07-21.58.47"}}

I assume you don't need the removed information as it comprises data already included in the output (the timestamp) and static strings (StatManagerLog).

You may then select the entries that you need, e.g., by state or timestamp:

$ sed 's/^\[.*/{/' file | jq -c --arg q 2023.06.07-21.58.47 'select(.RoundState.Timestamp == $q)'
{"RoundState":{"State":"Starting","Timestamp":"2023.06.07-21.58.47"}}
{"RoundState":{"State":"StandBy","Timestamp":"2023.06.07-21.58.47"}}
$ sed 's/^\[.*/{/' file | jq -c --arg q StandBy 'select(.RoundState.State == $q)'
{"RoundState":{"State":"StandBy","Timestamp":"2023.06.07-21.58.47"}}

... or by some more involved selection of any aggregate that you need.

🌐
InterServer
interserver.net › home › linux and commands › using jq for json parsing and manipulation in shell scripts
Using jq for JSON Parsing and Manipulation in Shell Scripts - Interserver Tips
October 7, 2025 - Quote your filters: Use single quotes around jq filters to prevent shell interpretation · Handle null values: Use the // operator to provide defaults for null values · Validate JSON input: Check that input is valid JSON before processing
🌐
Medium
lovethepenguin.com › validate-email-addresses-with-jq-4794e61b220f
Validate email addresses with JQ. In this article i will show you a handy… | by Konstantinos Patronas | Medium
July 20, 2024 - In this article i will show you a handy one-liner that can do the following, read from stdin a text file with email addresses, verify that the addresses are valid, and finally generate JSON output with the results on stdout, JSON the to go format for APIs so, generating JSON output is a very nice to have knowledge! Here is the one-liner which does all the job, might seem complicated but it isnt, i will explain everything you need to know! cat emails.txt | jq -Rn '[inputs | {"email": ., "valid": (test("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$")?)}]'
🌐
Notepad++ Community
community.notepad-plus-plus.org › topic › 18902 › format-my-json
Format my JSON | Notepad++ Community
May 21, 2025 - ... @Michael-Vincent I should clarify, when I say “external” - I use an NppExec script called “compile” that based on the extension runs an external program. In this case, .json launches the jq command on the current file.
🌐
Horizon3
docs.horizon3.ai › cli › guides › json-parsing-with-jq
Parsing JSON Results - HORIZON3
h3 gql pentests \ | jq -r '.data.pentests_page.pentests[] | {op_id, name, scheduled_at, state}' \ | jq -rsf $H3_CLI_HOME/filters/to_csv.jq · It's sometimes useful to view the structure of the JSON response payload:
🌐
Unstructured
docs.unstructured.io › api-reference › how-to › generate-schema
Generate a JSON schema for a file - Unstructured
You want to generate a schema for a JSON file that Unstructured produces, so that you can validate, test, and document related JSON files across your systems. Use a Python package such as genson to generate schemas for your JSON files. The genson package is not owned or supported by Unstructured. For questions and requests, see the Issues tab of the genson repository in GitHub. 1 · Install genson · Use pip to install the genson package. pip install genson · 2 · Install jq ·