From ea05d06f5a56d94d423fc697561a33ca3b8bf085 Mon Sep 17 00:00:00 2001 From: skewb1k Date: Mon, 19 Jan 2026 08:51:57 +0800 Subject: feature: add option to indent encoded output. --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index debe1ae..d2094b1 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Table of Contents * [encode_number_precision](#encode_number_precision) * [encode_escape_forward_slash](#encode_escape_forward_slash) * [encode_skip_unsupported_value_types](#encode_skip_unsupported_value_types) + * [encode_indent](#encode_indent) * [decode_array_with_array_mt](#decode_array_with_array_mt) Description @@ -201,6 +202,31 @@ This will generate: [Back to TOC](#table-of-contents) +encode_indent +---------------------------- +**syntax:** `cjson.encode_indent(indent)` + +If non-empty string provided, JSON values encoded by `cjson.encode()` will be +formatted in a human-readable way, using `indent` for indentation +at each nesting level. Also enables newlines and a space after colons. + +Example: + +```lua +local cjson = require "cjson" + +cjson.encode_indent(" ") +print(cjson.encode({ a = 1, b = { c = 2 } })) +-- { +-- "a": 1, +-- "b": { +-- "c": 2 +-- } +-- } +``` + +[Back to TOC](#table-of-contents) + decode_array_with_array_mt -------------------------- **syntax:** `cjson.decode_array_with_array_mt(enabled)` -- cgit v1.2.3-55-g6feb