ForHosting KIT · Text & AI

Pretty-print JSON text

Turn one cramped line of data into neatly indented text, so the 53-byte example comes back as 79 readable bytes, two spaces per level. Anything broken is reported with its exact position instead of being guessed at. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Text
{"name":"Ada","skills":["math","code"],"active":true}
You get
Indent
2
Bytes in
53
Bytes out
79

indent and validate with parse position

Why it checks before it indents

A formatter that only adds line breaks cannot tell whether the data is sound. This one first reads the whole text as strictly as a program would, and only then writes it back out with a fixed number of spaces per level. That reading is what guarantees that every brace has its partner, every quoted piece of text is closed, every number is valid and no comma is left dangling at the end of a list. If something fails, you get the position of the character where the reading stopped, so you can go straight to the bad comma, the quote or the leftover fragment instead of scanning an endless line by eye.

Reading, reviewing or shrinking

Two or four spaces are the usual choice when a person will read the result, for example in a code review, a support ticket or a log dump. Zero spaces does the opposite: once the check passes, everything comes back on one compact line, so you validate and shrink in a single step. The tool never repairs broken data and never reorders anything: what goes in valid comes out with the same content and only new spacing. If what you have is ordinary text that you want to turn into this format, that is a job for a different tool.

What tidying the text really involves

Unlike a pure visual formatter that only inserts newlines without understanding structure, a true pretty printer must parse first: only then can it guarantee that braces match, strings are closed, numbers are valid, and trailing commas are rejected. Zero indent yields a compact single-line serialization after a successful parse—useful when you want validation plus minification in one step. Two or four spaces are the usual choices for human review.

Byte counts for the input and output strings are included so pipelines can log expansion ratios when large minified blobs become multi-line documents.

What does indent 0 do?

The string is still fully parsed first, so invalid input still errors with a position.

Why does it say my text is not valid?

Because the strict reading stopped at one specific character, and the tool gives you its position. It is usually a leftover comma at the end of a list, a quote that was never closed or a brace without its partner. Fix that spot and try again.

Should I indent with two or four spaces?

Both are the usual choices when a person will review the result. If you choose nothing, you get two spaces per level, and you can pick any value from 0 to 8.

Does formatting change the order or content of my data?

No. Only the spaces and line breaks change. The tool does not reorder names, does not repair anything broken and does not fetch anything from outside your text, so the content comes out identical.

How much bigger does the text get once formatted?

The tool shows the size before and after, in bytes. In the example, a 53-byte text becomes 79 bytes with two spaces per level: the difference is the line breaks and the indentation.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/text/json-pretty-print

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/text/json-pretty-print \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"{\"name\":\"Ada\",\"skills\":[\"math\",\"code\"],\"active\":true}"}'
{
  "text": "{\"name\":\"Ada\",\"skills\":[\"math\",\"code\"],\"active\":true}"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "text.json_pretty_print",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_tokens20000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Minified, one-line, or inconsistently indented JSON is hard to read in code reviews, support tickets, and log dumps. This pretty-print JSON text tool accepts a raw JSON string, validates it with a strict parse, and re-serializes the value with consistent space indentation so nested objects and arrays line up predictably. When the payload is invalid, the task fails with invalid_input and reports the character position of the parse error so you can jump straight to the bad comma, quote, or trailing fragment. No key reordering side effects beyond standard JSON serialization, no network round trips, and no model tokens—just deterministic parse and stringify at the published $0.002 base price per successful call.

What pretty-printing a JSON string actually does

Pretty-printing JSON text means taking a string that claims to be JSON, parsing it into a value, and writing that value back out with a fixed number of spaces per nesting level. This capability takes your text field as the source string, runs a strict JSON parse, and returns a new text field with consistent indentation controlled by the optional indent parameter (an integer from zero through eight, defaulting to two spaces). The algorithm does not fetch remote schemas, does not repair broken JSON, and does not reorder object keys beyond the engine’s natural serialization order of the parsed object. That restraint keeps the contract simple: valid in, pretty out; invalid in, clear error with position.

Input contract, response fields, and parse error positions

Optionally send indent as an integer between zero and eight; omit it to use two spaces. When parse fails, the error message always includes a character position: engines that report “at position N” are echoed with that N, incomplete input is mapped to the end of the string, and other failures default to position zero so clients always have a cursor target. POST a JSON body with a required text string containing the document to format. Empty text, non-string text, and out-of-range indent values fail with invalid_input and are not billed. On success the response includes text (the pretty-printed document), indent (the effective spacing used), bytes_in (UTF-8 length of the source string), and bytes_out (UTF-8 length of the formatted result). Example: text equal to a minified object with nested arrays and indent equal to two returns multi-line JSON with two-space steps and matching braces. Example of failure: a truncated object missing a closing brace yields invalid_input mentioning the position near the end of the fragment. Pair this endpoint with your editor or log viewer by seeking to the reported offset; you do not need a second validation call.

Where pretty-print JSON text earns its keep

CI jobs can reject or rewrite config files that arrive minified from upstream generators, failing fast with a parse position when a release artifact is truncated mid-upload. Failed validation does not consume balance. Developers paste API responses into chat and tickets; pretty-print JSON text turns opaque one-liners into reviewable trees without installing a desktop formatter. Support tools show customers the exact offset of a malformed webhook body instead of a generic “invalid JSON” banner. Prefer this text-in, text-out contract when your pipeline already holds JSON as a string—logs, file contents, message bodies—rather than as a pre-parsed object.

Readable API and webhook dumps

Turn minified request or response bodies into indented JSON for tickets, chats, and post-mortems, with a parse position when the dump is truncated.

CI config and fixture checks

Validate and pretty-print JSON fixtures in pipelines; fail the job with invalid_input and a character offset when a generator emits broken syntax.

Support and editor jump-to-error

Show support agents and users the exact character position of a JSON syntax error so they can fix commas, quotes, or missing braces quickly.

How do I pretty-print a JSON string?

Send the JSON in the text field and optionally set indent (0–8, default 2). On success you receive indented text plus bytes_in and bytes_out.

What happens if the JSON is invalid?

The task fails with invalid_input and a message that includes the parse error character position so you can locate the bad token. Invalid input is not billed.

Does pretty-print JSON text sort object keys?

No. Keys keep the engine’s natural order after parse. The tool focuses on indentation and validation, not deterministic key sorting.

What does the pretty-print JSON text API cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →