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

[Feature] Add indent to tojson and toyaml context methods #11210

Open
3 tasks done
mjsqu opened this issue Jan 13, 2025 · 0 comments · May be fixed by #11211
Open
3 tasks done

[Feature] Add indent to tojson and toyaml context methods #11210

mjsqu opened this issue Jan 13, 2025 · 0 comments · May be fixed by #11211
Labels
enhancement New feature or request triage

Comments

@mjsqu
Copy link

mjsqu commented Jan 13, 2025

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

Add indent parameter to tojson and toyaml. These are straight mappings to the equivalent indent parameters in the respective json.dumps and yaml.safe_dump methods. Adding the indent parameter helps with debugging when developing with objects in Jinja.

Describe alternatives you've considered

No response

Who will this benefit?

This will help dbt macro developers to debug their processes.

Are you interested in contributing this feature?

Yes

Anything else?

This specifically came about because I wanted to make use of the sort_keys parameter, which is available in the tojson context method, but not the tojson Jinja filter:

{%- set myobj = {'a':{'ab':1},{'b':{'ba':2}}-%}

{# Not valid! #}
{{ myobj | tojson(sort_keys=False}}
{{ tojson(myobj,indent=2) }}

{# Valid #}
{{ tojson(myobj,sort_keys=False) }}
{{ myobj | tojson(indent=2}}

{# Valid after this change implemented #}
{{ tojson(myobj,sort_keys=False,indent=2) }}

Currently the last statement errors with:

Encountered an error: Error parsing inline query
Error while parsing node: inline_query BaseContext.tojson() got an unexpected keyword argument 'indent'

@mjsqu mjsqu added enhancement New feature or request triage labels Jan 13, 2025
@mjsqu mjsqu linked a pull request Jan 13, 2025 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant