{"record":{"id":"0012528400852827","repo":"languagetool-org/languagetool","slug":"json-output-format-makes-no-sense-for-automatic-ap","errorCode":null,"errorMessage":"JSON output format makes no sense for automatic application of suggestions","messagePattern":"JSON output format makes no sense for automatic application of suggestions","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"languagetool-commandline/src/main/java/org/languagetool/commandline/CommandLineParser.java","lineNumber":139,"sourceCode":"        checkArguments(\"--falsefriends\", i, args);\n        options.setFalseFriendFile(args[++i]);\n      } else if (args[i].equals(\"--bitextrules\")) {\n        checkArguments(\"--bitextrules\", i, args);\n        options.setBitextRuleFile(args[++i]);\n      } else if (args[i].equals(\"-c\") || args[i].equals(\"--encoding\")) {\n        checkArguments(\"-c/--encoding\", i, args);\n        options.setEncoding(args[++i]);\n      } else if (args[i].equals(\"-u\") || args[i].equals(\"--list-unknown\")) {\n        options.setListUnknown(true);\n        if (options.isTaggerOnly()) {\n          throw new IllegalArgumentException(\"You cannot list unknown words when tagging only\");\n        }\n      } else if (args[i].equals(\"-b\")) {\n        options.setSingleLineBreakMarksParagraph(true);\n      } else if (args[i].equals(\"--json\")) {\n        options.setJsonFormat();\n        if (options.isApplySuggestions()) {\n          throw new IllegalArgumentException(\"JSON output format makes no sense for automatic application of suggestions\");\n        }\n        if (options.isLineByLine()) {\n          throw new IllegalArgumentException(\"JSON output format is not implemented for \\\"line by line\\\" analysis\");\n        }\n        if (options.isBitext()) {\n          throw new IllegalArgumentException(\"JSON output format is not implemented for Bitext\");\n        }\n        if (options.isListUnknown()) {\n          throw new IllegalArgumentException(\"You cannot list unknown words in JSON output format\");\n        }\n      } else if (args[i].equals(\"-a\") || args[i].equals(\"--apply\")) {\n        options.setApplySuggestions(true);\n        if (options.isTaggerOnly()) {\n          throw new IllegalArgumentException(\"You cannot apply suggestions when tagging only\");\n        }\n        if (options.isJsonFormat()) {\n          throw new IllegalArgumentException(\"JSON output format makes no sense for automatic application of suggestions\");\n        }","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-commandline/src/main/java/org/languagetool/commandline/CommandLineParser.java#L121-L157","documentation":"JSON output is a machine-readable report of errors; applying suggestions rewrites the input text, which cannot be represented in JSON. When `--json` is parsed and applySuggestions was already enabled, parseOptions() throws this IllegalArgumentException.","triggerScenarios":"`languagetool -a --json file.txt` — --apply parsed before --json.","commonSituations":"Users combining auto-fix mode with structured output for pipelines; scripts merging fix-mode and report-mode profiles.","solutions":["Drop --json when using -a/--apply (the corrected text is written directly).","Drop -a/--apply and keep --json to get a machine-readable report you apply yourself.","Two-step approach: run with --json, programmatically apply the suggested replacements."],"exampleFix":"// before\nlanguagetool -a --json -l en file.txt\n// after\nlanguagetool --json -l en file.txt","handlingStrategy":"validation","validationCode":"List<String> a = Arrays.asList(args);\nif ((a.contains(\"--json\")) && (a.contains(\"-a\") || a.contains(\"--apply\"))) {\n  throw new IllegalArgumentException(\"--json cannot be combined with -a/--apply\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  new CommandLineParser().parseOptions(args);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"JSON output format makes no sense\")) {\n    System.err.println(\"Use --json for a report OR -a/--apply to rewrite text, not both.\");\n  }\n}","preventionTips":["Remember --json is report-only; it never rewrites files.","For auto-fix pipelines, use -a without --json.","To get both fixes and structured data, run --json and apply suggestions programmatically."],"tags":["cli","conflicting-flags","json"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}