forked from mpx/lua-cjson
-
Notifications
You must be signed in to change notification settings - Fork 130
feature: add option to indent encoded output #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
skewb1k
wants to merge
1
commit into
openresty:master
Choose a base branch
from
skewb1k:feat/pretty-encoding
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
justinmk
reviewed
Aug 22, 2025
a40e320 to
912817c
Compare
skewb1k
added a commit
to skewb1k/neovim
that referenced
this pull request
Aug 25, 2025
Problem: There is no straightforward way to pretty-print objects as JSON. The existing `vim.inspect` outputs LON. Solution: Introduce `pretty` option for `vim.json.encode()`, which enables pretty-formatting when table provided or `true`. Supports the following keys: - indent: (integer|string) (default 2) Controls how nested levels are indented. - If a integer: indents that many spaces per nesting level. - If a string: that string is used for the indentation. - item_separator: (string) (default "\n") Separator inserted between array elements and object members. - key_separator: (string) (default " ") Separator inserted after the colon between an object key and its value. Adapts PR to upstream: openresty/lua-cjson#114.
skewb1k
added a commit
to skewb1k/neovim
that referenced
this pull request
Aug 25, 2025
Problem: There is no straightforward way to pretty-print objects as JSON. The existing `vim.inspect` outputs LON. Solution: Introduce `pretty` option for `vim.json.encode()`, which enables pretty-formatting when table provided or `true`. Supports the following keys: - indent: (integer|string) (default 2) Controls how nested levels are indented. - If a integer: indents that many spaces per nesting level. - If a string: that string is used for the indentation. - item_separator: (string) (default "\n") Separator inserted between array elements and object members. - key_separator: (string) (default " ") Separator inserted after the colon between an object key and its value. Adapts PR to upstream: openresty/lua-cjson#114.
skewb1k
added a commit
to skewb1k/neovim
that referenced
this pull request
Aug 25, 2025
Problem: There is no straightforward way to pretty-print objects as JSON. The existing `vim.inspect` outputs LON. Solution: Introduce `pretty` option for `vim.json.encode()`, which enables pretty-formatting when table provided or `true`. Supports the following keys: - indent: (integer|string) (default 2) Controls how nested levels are indented. - If a integer: indents that many spaces per nesting level. - If a string: that string is used for the indentation. - item_separator: (string) (default "\n") Separator inserted between array elements and object members. - key_separator: (string) (default " ") Separator inserted after the colon between an object key and its value. Adapts PR to upstream: openresty/lua-cjson#114.
skewb1k
added a commit
to skewb1k/neovim
that referenced
this pull request
Aug 26, 2025
Problem: There is no straightforward way to pretty-print objects as JSON. The existing `vim.inspect` outputs LON. Solution: Introduce `pretty` option for `vim.json.encode()`, which enables pretty-formatting when table non-nil or `true`. Adapts PR to upstream: openresty/lua-cjson#114.
912817c to
79f5497
Compare
skewb1k
added a commit
to skewb1k/neovim
that referenced
this pull request
Aug 26, 2025
Problem: There is no straightforward way to pretty-print objects as JSON. The existing `vim.inspect` outputs LON. Solution: Introduce an `indent` option for `vim.json.encode()` which enables human-readable output with configurable indentation. Adapts PR to upstream: openresty/lua-cjson#114.
|
@zhuizhuhaomeng does this look like a change that openresty/lua-cjson would be open to? Should we send this change to https://github.com/mpx/lua-cjson , does openresty/lua-cjson still sync from there ? |
|
Sure. |
79f5497 to
862b6c5
Compare
Author
|
I noticed that some test names were not unique. I believe it's now ready for review. |
zhuizhuhaomeng
approved these changes
Sep 1, 2025
862b6c5 to
1b17610
Compare
skewb1k
added a commit
to skewb1k/neovim
that referenced
this pull request
Sep 4, 2025
Problem: There is no straightforward way to pretty-print objects as JSON. The existing `vim.inspect` outputs LON. Solution: Introduce an `indent` option for `vim.json.encode()` which enables human-readable output with configurable indentation. Adapts PR to upstream: openresty/lua-cjson#114.
justinmk
pushed a commit
to neovim/neovim
that referenced
this pull request
Sep 7, 2025
Problem: There is no straightforward way to pretty-print objects as JSON. The existing `vim.inspect` outputs LON. Solution: Introduce an `indent` option for `vim.json.encode()` which enables human-readable output with configurable indentation. Adapts PR to upstream: openresty/lua-cjson#114
dundargoc
pushed a commit
to dundargoc/neovim
that referenced
this pull request
Sep 27, 2025
Problem: There is no straightforward way to pretty-print objects as JSON. The existing `vim.inspect` outputs LON. Solution: Introduce an `indent` option for `vim.json.encode()` which enables human-readable output with configurable indentation. Adapts PR to upstream: openresty/lua-cjson#114
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds
cjson.encode_indent(indent)option.If non-empty string provided, JSON values encoded by
cjson.encode()will be formatted in a human-readable way, usingindentfor indentation at each nesting level. Also enables newlines and a space after colons. Must contain only spaces, tabs, line feeds, or carriage returns.Example: