Các lỗi JSON thường gặp
- Tìm hiểu
- Sửa
JSON syntax is strict, and a small mistake makes it unreadable. Here are the common mistakes to check when Format and Validate JSON shows "The JSON is malformed".
Các bước
- Paste the JSON into "Before".
- Press "Format".
- If there is an error, "The JSON is malformed" is shown.
- Check the common mistakes below in order and fix them.
Lỗi thường gặp
- An extra comma after the last item: {"a": 1, "b": 2,} is wrong. Delete the last comma.
- Using single quotes: JSON uses only double quotes (").
- No quotes on item names: {name: "Yamada"} is wrong. Write {"name": "Yamada"}.
- Unclosed brackets: match the numbers of { and }, [ and ].
- Missing commas: a comma is needed between items.
- Writing comments: JSON can't have comments.
- Full-width symbols: full-width brackets, quotes, colons and commas can't be used.
- Wrong value notation: true, false and null are lowercase. True and NULL are wrong.
- Number notation: leading zeros (007) and trailing decimal points are wrong.
- Line breaks in strings: a raw line break can't go inside a string. Write "\n".
- Quotes in strings: they need escaping as \".
Example of the correct form
Inside braces, join item names and values with colons and separate items with commas. Enclose item names and strings in double quotes.
Tips for fixing
- Look first at the place you edited last
- If long, split it in half and narrow down which half has the error
- Fix a bit at a time until it can be formatted
Finding full-width symbols
Though they look similar, full-width brackets and quotes differ in width from half-width. Search for full-width symbols in a text editor.
A useful approach
These are common mistakes in JSON edited by hand or in Notepad. After editing, always check with this tool.
Ví dụ
After editing a configuration file it couldn't be loaded. Investigation showed the quotes on the item names were full-width. Changed to half-width and solved it.
Common stumbling blocks
- Fixed but still an error: there are other errors. Check repeatedly.
- Can't tell where the error is: shorten and try.
Frequently asked questions
Can a JavaScript object be pasted as it is?
If item names lack quotes, it's an error. Rewrite it in JSON syntax.
Tóm tắt
Watch for extra commas, quotes, brackets and full-width characters. After fixing, check again.
Dùng “Định dạng và kiểm tra JSON” (miễn phí)Công cụ hay dùng cùng
- Chuyển đổi CSV và JSON: Chuyển đổi giữa CSV và JSON ngay lập tức.
- Chuyển đổi tệp và Base64: Chuyển đổi giữa tệp và văn bản Base64.
- Xóa dòng trùng lặp và sắp xếp danh sách: Xóa các dòng trùng lặp và sắp xếp chúng.
Nếu hướng dẫn này hữu ích, một khoản ủng hộ nhỏ sẽ là niềm động viên lớn.
Gửi tiền ủng hộ (¥300)Tặng quà (danh sách mong muốn Amazon)