{"record":{"id":"dc5c6688ce63ed9a","repo":"JamesNK/Newtonsoft.Json","slug":"invalid-javascript-string-quote-character-valid-q","errorCode":null,"errorMessage":"Invalid JavaScript string quote character. Valid quote characters are ' and \".","messagePattern":"Invalid JavaScript string quote character\\. Valid quote characters are ' and \"\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/JsonTextWriter.cs","lineNumber":114,"sourceCode":"                {\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                }\n\n                _quoteChar = value;\n                UpdateCharEscapeFlags();\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets which character to use for indenting when <see cref=\"JsonWriter.Formatting\"/> is set to <see cref=\"Formatting.Indented\"/>.\n        /// </summary>\n        public char IndentChar\n        {\n            get => _indentChar;\n            set\n            {\n                if (value != _indentChar)\n                {\n                    _indentChar = value;","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/JsonTextWriter.cs#L96-L132","documentation":"Thrown by the JsonTextWriter.QuoteChar setter when assigning a character other than double-quote (\") or single-quote ('). Valid JSON permits only these two as string/property delimiters, so any other char (backtick, space, etc.) is rejected with ArgumentException at configuration time rather than producing malformed output.","triggerScenarios":"Setting writer.QuoteChar to any char except \" or '; reading QuoteChar from config as a char/string and assigning an invalid value; passing a unicode whitespace or punctuation char.","commonSituations":"Config that supplies a wrong quote character; interop code assuming backticks are valid; parsing a 'quote style' setting into a char incorrectly.","solutions":["Use '\"' (default, maximally compatible) or '\\'' for single-quoted output.","Validate config before assignment: if (c == '\\\"' || c == '\\'') writer.QuoteChar = c;.","For single-quoted JS-style output set both QuoteChar='\\'' and StringEscapeHandling.EscapeSingleQuotes (as appropriate)."],"exampleFix":"// before\nwriter.QuoteChar = '`';\n\n// after\nwriter.QuoteChar = '\"';","handlingStrategy":"validation","validationCode":"if (configuredQuote == '\"' || configuredQuote == '\\'')\n{\n    writer.QuoteChar = configuredQuote;\n}","typeGuard":"static bool IsValidQuoteChar(char c) => c == '\"' || c == '\\'';","tryCatchPattern":null,"preventionTips":["Allow only '\"' or '\\'' as quote characters.","Parse config strings to a single char and validate before assignment.","Default to '\"' for maximum JSON compatibility."],"tags":["formatting","validation","json-spec"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}