Fix JSON errors with JSONLint
Find a trailing comma. Deal with JSON. Understand what a valid result is and what it's not. Short example and real screenshots. Properly handle JSON.

Here is an example of what a json looks like with a trailing comma in the fake json. This type of syntax error could break your import/automation. You can check for syntax errors before you attempt to import after making the fix using JSONLint. Note: Doing this in a browser enviroment using fake data. You don't want to be working with real passwords/tokens/customer data online.
1. Paste a small example
- JSONLint (opens in a new tab) 2. Click to enable editor 3. Copy/paste the text below. It has a trailing comma after last value (on purpose). 4. Click on Validate button.
text below:
{
"item": "Notebook",
"quantity": 2,
}
2. Remove the trailing comma
Example: Giving invalid json E008 Line/column closing brace is highlighted. That's where the error is detected.
Look at comma in line just above.
Invalid JSON.
- Do not comma after 2. (Leave the comma after "Notebook". You got another field after it) 2. Press the validate button again
Watch out
Valid JSON is a JSON conforming to the syntax. It doesn't mean the address is valid, or that the order is there, or that that particular app will expect those fields to be there. Be sure to check what fields they expect where, and what should be in those fields. Before attempting to load/submit data.
3. Copy the corrected result
The corrected object returns Valid JSON. It contains two fields: item with a text value and quantity with a number value.
{
"item": "Notebook",
"quantity": 2
}
The last JSON object is where we have the "quantity": 2 and the } for that object. No comma after that last numeric 2 before the }. There should be a comma after "Notebook" since it is the previous item property. Before the quantity property.
You can either copy that corrected text to copy to the JSON field of destination or you can use a plain text editor. The numeric 2 won't be quoted if you are copying to a destination that expects a number. "2" is text. Try a harmless record before a big file.
If validation still fails
First get the one that has been reported. Then the one before that. Use regular double quotes for field names and text. Use commas to separate the fields. Close of braces or brackets. You can see what's possible here JSON syntax reference (opens in a new tab).
Put the original in some storage. If you're going to keep going, for the auto-repair, see what the repaired values are, compared to the original. Syntax repair has no idea what you're trying to say.
Sources: JSON.org (opens in a new tab); JSONLint privacy policy (opens in a new tab); JSONLint source and licence (opens in a new tab). Screenshots show JSONLint with fictional data and are cropped to the relevant controls.
JSONLint source (opens in a new tab). Licence and screenshot notices.
Share this post
From holdmytwist.com/blog/fix-json-errors-jsonlint/


