Fixing JSON errors: quotes, commas, and values that do not belong
To fix invalid JSON, check the reported position for a trailing comma, single quotes, or a newline inside a string. The examples below show each correction and explain when syntax validation is enough.
The converter reports a parse error, but the payload looks close to correct. Start at the reported position and inspect the surrounding text. A missing quote earlier in the document can make a later character look like the problem.
Fix a JSON single quotes error
JavaScript allows object literals with unquoted property names. JSON requires object names to be strings enclosed in double quotes.
{name: 'Maya'}{"name":"Maya"}If you have a JavaScript object in running code, use JSON.stringify to produce its JSON representation. For text copied from a document, correct the syntax before parsing it.
Fix a JSON trailing comma error
A comma separates members or array elements. After the final item, the closing bracket or brace should follow without another comma.
{"tags":["billing","retry",]}{"tags":["billing","retry"]}Comments are another possible cause. Text such as // retry later is not part of JSON syntax. If a configuration format permits comments, confirm how that format should be read before passing it to a strict JSON parser.
Check the values themselves
JSON supports strings, numbers, booleans, null, objects, and arrays. JavaScript's undefined, NaN, and Infinity do not have JSON spellings. Choose a supported value that matches the meaning of the field.
Replacing a missing value with null may be appropriate in your application, but it changes the data. Do not make that substitution just to silence an error if a field is required.
These syntax rules come from the JSON format specification, RFC 8259. Its grammar also excludes numbers with leading zeros, so 01 is invalid as a number. Use "01" if those characters are a code or identifier.
Escape a newline inside a string
A line break between object members is fine. A literal newline inside a quoted string must be represented with an escape.
{"message":"First line\nSecond line"}The parser returns a string containing a newline. Keep the escape in the JSON text; the decoded string and its serialized representation have different appearances.
Check meaning after syntax
The text {"attempt":"three"} is valid JSON. An application expecting an integer may still reject it. A validator for JSON syntax cannot know your application's field requirements.
In the converter, choose JSON Validator and use Jump to error to select the reported position. Once the syntax passes, compare the result with the receiving application's documented schema. Keep a copy of the original payload if you need to explain exactly what changed.