seo.json_formatter.how_desc
- seo.json_formatter.how_step1
- seo.json_formatter.how_step2
- seo.json_formatter.how_step3
- seo.json_formatter.how_step4
seo.json_formatter.how_example
Форматирование и проверка данных JSON. Украшение или минификация JSON-строк.
Форматтер JSON — это инструмент, который берёт неаккуратные, неформатированные данные JSON и преобразует их в чистый, читаемый формат с правильными отступами и переносами строк. Он также проверяет, что ваш JSON синтаксически корректен.
seo.json_formatter.how_desc
seo.json_formatter.how_example
JSON (JavaScript Object Notation) был определён Дугласом Крокфордом и стандартизирован в RFC 8259 (2017). JSON — это лёгкий, языконезависимый формат данных, основанный на синтаксисе объектов JavaScript. Он стал доминирующим форматом для веб-API, конфигурационных файлов и обмена данными, во многом заменив XML во многих приложениях.
JSON formatting does not validate data safety. Always validate and sanitize JSON content from untrusted sources before using it in your application. Learn about encoding security
Каждый язык программирования может форматировать (украшать) и минифицировать JSON. Вот примеры:
// Beautify (pretty print)
$formatted = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
// Result: formatted with 4-space indent
// Minify (compact)
$minified = json_encode($data);
// Result: no whitespace
// With custom options
$json = json_encode($data,
JSON_PRETTY_PRINT |
JSON_UNESCAPED_UNICODE |
JSON_UNESCAPED_SLASHES
);
// Parsing (with error handling)
$data = json_decode($jsonString, true);
if (json_last_error() !== JSON_ERROR_NONE) {
echo "JSON Error: " . json_last_error_msg();
}
// Beautify with 2-space indent
const formatted = JSON.stringify(data, null, 2);
// Beautify with 4-space indent
const formatted = JSON.stringify(data, null, 4);
// Minify (compact)
const minified = JSON.stringify(data);
// Parse with error handling
try {
const data = JSON.parse(jsonString);
} catch (error) {
console.error("JSON parse error:", error.message);
}
// Replacer function (custom serialization)
const json = JSON.stringify(data, (key, value) => {
// Exclude private fields
if (key.startsWith('_')) return undefined;
return value;
}, 2);
import json
# Beautify with 2-space indent
formatted = json.dumps(data, indent=2)
# Beautify with sorted keys
formatted = json.dumps(data, indent=2, sort_keys=True)
# Minify (compact)
minified = json.dumps(data, separators=(',', ':'))
# separators removes spaces after commas and colons
# Parse with error handling
try:
data = json.loads(json_string)
except json.JSONDecodeError as e:
print(f"JSON error: {e.msg} at line {e.lineno}")
# Pretty print to console
print(json.dumps(data, indent=2))
import (
"encoding/json"
"fmt"
)
// Beautify with indent
formatted, err := json.MarshalIndent(data, "", " ")
if err != nil {
fmt.Println("JSON marshal error:", err)
}
// Minify (compact)
minified, err := json.Marshal(data)
// Parse with error handling
var data MyStruct
err := json.Unmarshal([]byte(jsonString), &data)
if err != nil {
fmt.Println("JSON unmarshal error:", err)
}
// Custom indentation
formatted, _ := json.MarshalIndent(data, ">", "----")
// Prefix: >, indent: ----
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
// Beautify
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.create();
String formatted = gson.toJson(data);
// Minify
Gson gson = new Gson();
String minified = gson.toJson(data);
// Parse with error handling
try {
MyObject obj = gson.fromJson(jsonString, MyObject.class);
} catch (JsonSyntaxException e) {
System.err.println("JSON error: " + e.getMessage());
}
require 'json'
# Beautify
formatted = JSON.pretty_generate(data)
# Default: 2-space indent
# Beautify with custom indent
formatted = JSON.pretty_generate(data, indent: ' ')
# 4-space indent
# Minify
minified = JSON.generate(data)
# Parse with error handling
begin
data = JSON.parse(json_string)
rescue JSON::ParserError => e
puts "JSON error: #{e.message}"
end
using Newtonsoft.Json;
// Beautify (pretty print)
string formatted = JsonConvert.SerializeObject(data,
Formatting.Indented);
// Minify (compact)
string minified = JsonConvert.SerializeObject(data,
Formatting.None);
// Parse with error handling
try
{
var obj = JsonConvert.DeserializeObject<MyObject>(jsonString);
}
catch (JsonException ex)
{
Console.WriteLine($"JSON error: {ex.Message}");
}
Working with JWT tokens? Our JWT Decoder decodes and formats the JSON header and payload from JWT tokens.
Have Base64-encoded JSON? First use our Base64 Decoder to decode, then format the resulting JSON.
Passing JSON in URL parameters? Encode it with our URL Encoder after minifying for compact URLs.