--json
- Accepted by
opengrep scan,opengrep ci,opengrep test,opengrep show
Prints one JSON document on standard output. Its top level holds version, results, errors, paths, skipped_rules and interfile_languages_used.
Each entry of results names the rule as check_id and the file as path, gives the start and end of the match as a line, a column and a byte offset, and holds the rest under extra: the message with its metavariables replaced, the metavars themselves, the metadata and severity of the rule, the matched lines, and a fingerprint that does not change when the code moves. --time adds a time object, and --matching-explanations an explanations array.
--json-output writes the same document to a file, in addition to the output on standard output. Only one format can be printed to standard output, so --json cannot be combined with --sarif, --emacs, --vim and the other formats.
Examples
The shape of the document
rules: - id: find-eval pattern: eval(...) message: found eval languages: [python] severity: WARNINGeval(1)$ opengrep scan --config rule.yaml --json app.py 2>/dev/null | jq .
{
"version": "X.Y.Z",
"results": [
{
"check_id": "find-eval",
"path": "app.py",
"start": {
"line": 1,
"col": 1,
"offset": 0
},
"end": {
"line": 1,
"col": 8,
"offset": 7
},
"extra": {
"metavars": {},
"message": "found eval",
"metadata": {},
"severity": "WARNING",
"fingerprint": "cc2ee9ac3b87e874db7ede72562f586db0607e44a6ebc8879fc1772bd2699a2f302d90e0cf6bde9dce450cb0891646fb0b3d70263351681e1d2e48ca0d26d960_0",
"lines": "eval(1)",
"is_ignored": false,
"validation_state": "NO_VALIDATOR",
"engine_kind": "Opengrep"
}
}
],
"errors": [],
"paths": {
"scanned": [
"app.py"
]
},
"interfile_languages_used": [],
"skipped_rules": []
}