Format, validate or minify JSON: which task do you need?
Understand JSON syntax checks, readable formatting and compact output without confusing validation with API correctness.
Published
Three operations, three purposes
Formatting adds readable indentation. Validation checks whether text follows JSON syntax. Minification removes insignificant whitespace. None of these tasks, by itself, proves that an API will accept the data.
For example, {"age":"twenty"} is valid JSON. An endpoint expecting a numeric age can still reject it. Schema rules and application requirements are separate from JSON syntax.
Fix syntax before arranging the output
JSON property names and string values use double quotes. Trailing commas and comments are not part of standard JSON. Copying a JavaScript object literal into a JSON field can therefore produce an error even when the object works in JavaScript.
Start with a small sample such as {"name":"Ada","items":[1,2]}. If the sample works but your full payload fails, inspect the reported position and the preceding separator or quote. An error location often points to where parsing became impossible, rather than exactly where the mistake began.
Read a formatted copy
Use the JSON formatter when nesting makes a response hard to inspect. Check which object owns each field and whether a value is a string, number, boolean, array or null. Readable indentation makes these relationships easier to see.
Do not paste credentials or personal records into an unfamiliar service. Use a redacted test fixture when debugging with someone else. Keep an untouched original if the payload will be used to investigate a production problem.
Minify only after review
Use the JSON minifier for a compact transport or storage copy after reviewing the readable source. It does not remove unnecessary records, shorten field values or compress binary data. Those require separate changes.
For large integers, check how your consuming language represents numbers; JavaScript numbers cannot represent every arbitrarily large integer exactly. If byte-for-byte fidelity matters, preserve the original and verify the tool's serialization behaviour before using its output in production.
Sources
Sources reviewed .
