{"record":{"id":"e6c77096a6f6f73c","repo":"JamesNK/Newtonsoft.Json","slug":"indentation-value-must-be-greater-than-0","errorCode":null,"errorMessage":"Indentation value must be greater than 0.","messagePattern":"Indentation value must be greater than 0\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/JsonTextWriter.cs","lineNumber":97,"sourceCode":"                {\n                    throw new ArgumentNullException(nameof(value));\n                }\n\n                _arrayPool = value;\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets how many <see cref=\"JsonTextWriter.IndentChar\"/>s to write for each level in the hierarchy when <see cref=\"JsonWriter.Formatting\"/> is set to <see cref=\"Formatting.Indented\"/>.\n        /// </summary>\n        public int Indentation\n        {\n            get => _indentation;\n            set\n            {\n                if (value < 0)\n                {\n                    throw new ArgumentException(\"Indentation value must be greater than 0.\");\n                }\n\n                _indentation = value;\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets which character to use to quote attribute values.\n        /// </summary>\n        public char QuoteChar\n        {\n            get => _quoteChar;\n            set\n            {\n                if (value != '\"' && value != '\\'')\n                {\n                    throw new ArgumentException(@\"Invalid JavaScript string quote character. Valid quote characters are ' and \"\".\");\n                }","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/JsonTextWriter.cs#L79-L115","documentation":"Thrown by the JsonTextWriter.Indentation setter when the supplied value is less than zero. Indentation controls how many IndentChar characters are emitted per hierarchy level under Formatting.Indented. Negative indentation is nonsensical, so the setter rejects it with ArgumentException. Note the message says 'greater than 0' but the guard is `< 0`, so zero is actually accepted (meaning flat output) despite the wording.","triggerScenarios":"Assigning writer.Indentation = -1; computing indentation from config/arithmetic that can go negative.","commonSituations":"Config-driven indentation without validation; subtractive math producing a negative; misreading the message and assuming 0 is illegal.","solutions":["Use a non-negative integer (0 disables visible indentation; typical is 2).","Validate config: writer.Indentation = Math.Max(0, configured);.","If you only need pretty-printing, set Formatting = Formatting.Indented and leave Indentation at default (2)."],"exampleFix":"// before\nwriter.Indentation = -1;\n\n// after\nwriter.Indentation = 2;","handlingStrategy":"validation","validationCode":"writer.Indentation = Math.Max(0, configuredIndentation);","typeGuard":"static bool IsValidIndentation(int v) => v >= 0;","tryCatchPattern":null,"preventionTips":["Use 2 (common) or 0 (flat) for Indentation; never negative.","Clamp config values with Math.Max(0, value).","Note: 0 is accepted despite the message implying 'greater than 0'."],"tags":["formatting","configuration","validation"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}