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 support for setting subobjects via JSON pointer in set statements. #202

Merged
merged 1 commit into from
Jun 9, 2021

Conversation

brycelelbach
Copy link
Contributor

This PR adds support for JSON pointers to set statements, e.g. {% set x.y = 1 %} sets the y member of x to 1.

Previously, you could use JSON pointer syntax in a set statement, but it did not work as you might expect. {% set x.y = 1 %} would render without errors, but {{ x.y }} would not be set to 1.

Tests are included. In addition to adding tests for set statements with JSON pointers, I also added tests for setting variables that are in the original JSON data, as such tests seemed to be missing.

I also updated the README.md section to explain that JSON pointers work to set sub-objects and that the set statement will not modify the underlying JSON object you pass in to a render call.

E.g. `{% set x.y = 1 %}` sets the `y` member of `x` to 1.
@pantor pantor merged commit 798a0b9 into pantor:master Jun 9, 2021
@pantor
Copy link
Owner

pantor commented Jun 9, 2021

LGTM. Thanks so much!

@brycelelbach brycelelbach deleted the set_statement_json_pointers branch July 2, 2021 01:48
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.

2 participants