JSON をフォーマット・整形する方法
圧縮された JSON を、読みやすいインデント付きの形式に変換します。
问题
JSON が 1 行の長い文字列になっており、デバッグや編集のために読みやすくする必要があります。
前提条件
- JSON 構造の理解
- インデントへの習熟
ステップ
-
1. Validate the input JSON
Before formatting, confirm the input is valid JSON. If there are syntax errors (trailing commas, missing quotes), the formatter will fail. Fix any syntax issues first.
入力{"name":"John","age":30,"city":"NYC"}输出valid JSON -
2. Apply indentation and line breaks
Use a JSON formatter to add line breaks after each key-value pair and indent nested objects and arrays. A common indent size is 2 spaces. The formatter adds whitespace without changing the data.
入力{"name":"John","age":30}输出{\n "name": "John",\n "age": 30\n} -
3. Review and use the formatted output
Read through the formatted JSON to verify the structure. Proper indentation makes nested objects and arrays easy to follow. Copy the formatted JSON for editing or documentation.
入力formatted JSON输出readable structure
期待される結果
一貫したインデントと改行を備えた、有効で人が読みやすい JSON 文字列。
よくあるエラー
- Formatter fails with 'Unexpected token'
- The input has a syntax error such as a trailing comma, single quotes, or a missing bracket. Fix the JSON before formatting.
- Unicode characters become escape sequences
- Some formatters escape non-ASCII by default. Use a formatter with an 'ensure ASCII false' option to keep Unicode readable.
トラブルシューティング指引
- If the output looks wrong, validate the input JSON first.
- For very large JSON, use a streaming formatter to avoid memory issues.
セキュリティ上の制限
- Formatting JSON does not execute any code. However, do not trust JSON from untrusted sources without validation.