Skip to content
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

Add indenting to toyaml & tojson context methods #11211

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mjsqu
Copy link

@mjsqu mjsqu commented Jan 13, 2025

Resolves #11210

Problem

Printing of large JSON objects for debugging can be difficult when using the inbuilt context method tojson() rather than the Jinja filter, which allows indenting | tojson(indent=4). The underlying methods used, json.dumps and yaml.safe_dump, have ready-made indent parameters which can be leveraged.

Solution

Adds indent parameter to tojson and toyaml context methods, passing the value directly to json.dumps and yaml.safe_dump respectively. The change mirrors the functionality of sort_keys.

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@mjsqu mjsqu requested a review from a team as a code owner January 13, 2025 22:52
@cla-bot cla-bot bot added the cla:yes label Jan 13, 2025
@github-actions github-actions bot added the community This PR is from a community member label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes community This PR is from a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add indent to tojson and toyaml context methods
1 participant