# json.indent

The `json.indent` function reformats a JSON string with line breaks and indentation. Use it to make JSON text
from a command or file readable. To encode a value and format it in one call, use
[`json.encode_indent`](/functions/automation/json.encode_indent).

## Usage

```python
json.indent(str, prefix = "", indent = "\t")
```

## Arguments

- **`str`**
  Required. A valid JSON string. It must be passed positionally.
- **`prefix`**
  (Optional) Keyword-only. Text added at the start of every line after the first. Defaults to 
  `""`
  .
- **`indent`**
  (Optional) Keyword-only. The text used for one level of indentation. Defaults to a tab character.

## Returns

A string with the same JSON content, spread across lines. Key order is preserved as written in the input.

## Examples

### Indent with two spaces

```python
print(json.indent('{"a":1,"b":[1,2]}', indent = "  "))
```

```text
{
  "a": 1,
  "b": [
    1,
    2
  ]
}
```

### Use the default tab indentation

```python
print(json.indent('{"a":1,"b":[1,2]}'))
```

```text
{
	"a": 1,
	"b": [
		1,
		2
	]
}
```

### Format command output

```python
result = atmos.run(
    ["describe", "component", "vpc", "--stack=dev", "--format=json"],
    output = "capture",
)
output = json.indent(result.stdout, indent = "  ")
```

## Errors

- Input that is not valid JSON fails with a message such as
  `json.indent: invalid character 'b' looking for beginning of object key string`.
- Passing `prefix` or `indent` positionally fails, because both are keyword-only.

## Related

- [`json.encode_indent`](/functions/automation/json.encode_indent) encodes a value and indents it in one call.
- [`json.encode`](/functions/automation/json.encode) and [`json.decode`](/functions/automation/json.decode)
- [Atmos Automation Language](/automation/language) and the [script step](/steps/type/script)
