Bỏ qua đến nội dung chính
FreeOnlineTools Go
Tiếng Việt
how-to

Cách Định dạng và Xác thực Dữ liệu JSON Từng Bước Một

By FreeOnlineTools Team · Updated 2026-09-02

Quick Answer

Để định dạng JSON: dán JSON vào JSON Formatter và output beautify với indent đúng xuất hiện ngay. Để validate: công cụ tự động kiểm tra syntax và hiển thị lỗi với vị trí nếu không hợp lệ. Tất cả xử lý xảy ra cục bộ.

Introduction

JSON (JavaScript Object Notation) là định dạng dữ liệu phổ biến nhất cho web API và tệp cấu hình. JSON thô từ API thường được minify thành một dòng, khó đọc. Định dạng (còn gọi beautifying hoặc pretty-printing) thêm indent và ngắt dòng. Validation kiểm tra xem syntax JSON có đúng —một dấu phẩy sai vị trí có thể phá整个 ứng dụng.

Step by Step

  1. Open the JSON Formatter tool

    Go to the JSON Formatter tool page. The tool accepts any JSON string as input — objects, arrays, or nested structures.

  2. Paste your JSON data

    Paste the JSON you want to format or validate into the input textarea. This could be an API response, a config file, or a JSON string from your code.

  3. Review the formatted output

    The tool parses your JSON and re-serializes it with 2-space indentation and line breaks. The formatted output appears instantly in the result field. If the JSON is invalid, an error message appears with the location of the syntax problem.

  4. Check validation status

    If the JSON is valid, the tool shows a success indicator and the formatted output. If invalid, it displays the parse error — such as 'Unexpected token at position 42' — so you can fix the syntax issue in your source.

  5. Copy or minify the result

    Use the Copy button to copy the formatted JSON to your clipboard. Some tools also offer a Minify button to remove all whitespace — useful for reducing payload size in production.

Examples

Format minified JSON

Input: {"name":"Alice","age":30,"roles":["admin","user"]}

Output: { "name": "Alice", "age": 30, "roles": ["admin", "user"] }

Detect invalid JSON (trailing comma)

Input: {"a":1,"b":2,}

Output: Error: Unexpected token } at position 11

Detect invalid JSON (single quotes)

Input: {'name':'Alice'}

Output: Error: Unexpected token ' at position 1

Common Problems

  • Using single quotes for strings —JSON requires double quotes for all strings and keys.
  • Trailing commas after the last item —JSON does not allow a comma before } or ].
  • Comments in JSON —standard JSON does not support // or /* */ comments. Use JSONC or JSON5 if you need comments.
  • Unquoted keys —unlike JavaScript object literals, JSON requires all keys to be in double quotes.
  • Undefined, NaN, or Infinity values —JSON only supports null, not undefined or NaN.

Tips

  • Always validate JSON before sending it in an API request —a syntax error can cause a 400 Bad Request response.
  • Use minified JSON in production to save bandwidth, and formatted JSON in development for readability.
  • JSON does not support Date objects —serialize dates as ISO 8601 strings (e.g., "2026-09-02T00:00:00Z").
  • Use JSON.parse() in JavaScript to convert a JSON string to an object, and JSON.stringify() to convert an object to a JSON string.

Related Tools

Related Guides

References