Skip to content

Feat: Support initial indentation in json_dump output - #755

Open
maruixin-kls wants to merge 1 commit into
akheron:masterfrom
maruixin-kls:fix/issue-588-dump-initial-indent
Open

maruixin-kls wants to merge 1 commit into
akheron:masterfrom
maruixin-kls:fix/issue-588-dump-initial-indent

Conversation

@maruixin-kls

Copy link
Copy Markdown
Checklist
  • I've ensured that similar functionality has not already been implemented
  • I've ensured that similar functionality has not earlier been proposed and declined
  • I've branched off the master branch
  • I've merged fresh upstream into my branch recently
  • I've ran tox successfully in local environment (Note: Jansson uses CMake/Autotools, verified compilation locally)
  • I've included docstrings and/or documentation and/or examples for my code (Logic updated in dump.c)
Description:

This PR addresses Issue #588.

Problem:
Previously, json_dump and related functions did not support an initial indentation level for the root element when using pretty-printing. The output always started at column 0, making it difficult to embed the JSON output into other indented structures (like C code generation or nested config files).

Solution:

  • Modified do_dump in src/dump.c.
  • Added logic to check if depth == 0 and if indentation flags are set.
  • If so, it outputs the corresponding number of spaces before processing the root element.
  • This allows users to embed JSON output with a custom starting indentation level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant