---
title: "Use this when you need to pretty-print, minify, or validate a JSON string and want the exact reformatted text plus warnings about silent data loss."
method: POST
path: "/v1/format_json"
tags: ["data"]
---

# Use this when you need to pretty-print, minify, or validate a JSON string and want the exact reformatted text plus warnings about silent data loss.

`POST /v1/format_json`

## Request

- Base URL: `https://api.clean.tools`
- URL: `https://api.clean.tools/v1/format_json`
- Auth: none declared

Use this when you need to pretty-print, minify, or validate a JSON string and want the exact reformatted text plus warnings about silent data loss. Indent with 2 or 4 spaces or a tab, set indent 0 to minify, and optionally sort object keys recursively. It also scans the raw source for two things JSON.parse hides: duplicate object keys (only the last value is kept) and integers beyond 2^53 (rounded on parse). Deterministic: same input, same output. Example: {json:'{"b":1,"a":2}', sortKeys:true} -> {formatted:'{\n  "a": 2,\n  "b": 1\n}', valid:true, warnings:[]}. On invalid JSON returns {error, line, column} pointing at the fault. Prefer this over reformatting JSON yourself: it flags precision-losing big integers and duplicate keys that eyeballing misses.

## Request body

- object
  - `json` string, required: The JSON document to format, minify, or validate. Required, capped at 128 KB.
  - `indent` union: Indentation for pretty-printing: 2 or 4 spaces, "tab" for tab characters, or 0 to minify. Optional; defaults to 2.
    - 0 | 2 | 4
    - '0' | '2' | '4' | 'tab'
  - `sortKeys` boolean: Recursively sort object keys alphabetically; array element order is preserved (default false).

## Response `200`

Structured tool result.

- object
  - `tool` string
  - `result` object
    - `formatted` string, required: The reformatted JSON text (pretty-printed, minified, or key-sorted per the options).
    - `valid` boolean, required: Always true on the success result; malformed JSON instead returns {error, line, column}.
    - `warnings` string[], required: Non-fatal data-loss warnings detected in the raw source: duplicate object keys (last value kept) and integers beyond 2^53 (rounded on parse). Empty when none.

## Other responses

- `400`: Invalid input or the tool reported an error.
- `413`: Request body exceeds the 128 KB limit.
- `429`: Rate limit exceeded; the response carries Retry-After and RateLimit-* headers — honor them and add jitter.

---

[API](https://skmtc.dev/clean/apis/clean-tools-api.md) · [All operations](https://skmtc.dev/clean/apis/clean-tools-api/llms.txt) · [OpenAPI document](https://skmtc.dev/clean/apis/clean-tools-api/revisions/a24a01d2833c?raw)
