How to format JSON without changing its values

Inspect a compact API response, keep significant spaces and large IDs intact, and tell syntax errors from data errors.

Begin with the original response

Suppose an inventory export contains {"id":9007199254740993,"label":"Tea tin","sizes":[2,4]}. You want to read the record and see which sizes it lists. Paste the exact response body into the JSON Formatter and choose two-space indentation. Exclude any Markdown fences from the pasted text.

Each property now has its own line. The space inside “Tea tin” belongs to the label. Spaces and line breaks between the properties are formatting, so you can change them without changing the information.

Keep an eye on long numbers and repeated keys

The example ID is one greater than 9007199254740992. A program that converts it into a JavaScript Number and then writes the number back can round those last digits. PocketKit checks the syntax and formats the original tokens, which keeps the digits exactly as entered.

If an object contains "size":2 followed by another "size":4, formatting reveals both entries. Software reading the object can disagree on which value to keep. Confirm which value belongs in the source and fix it there before passing the object on.

Fix one syntax issue at a time

A response that looks like {"sizes":[2,4,]} fails because a comma after the 4 promises another array item. Remove that last comma and format again. For an unquoted property such as {sizes:[2,4]}, add double quotes around sizes.

A successful format establishes that the input is valid JSON. To check whether your inventory API accepts it, verify that it expects a field named sizes, an array in that field, and numbers in that array. That requires the API’s own rules.

Choose the output for its next reader

Keep the indented form for review. Choose minify when you need a compact single line for a text field. Compare the ID and label with your original before saving the result to a downstream system.

References