-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Allow null values for jsonencode #54
Conversation
Codecov Report
@@ Coverage Diff @@
## master #54 +/- ##
=======================================
Coverage 70.53% 70.54%
=======================================
Files 79 79
Lines 7151 7153 +2
=======================================
+ Hits 5044 5046 +2
Misses 1664 1664
Partials 443 443
Continue to review full report at Codecov.
|
Thanks for looking at this! My intuition here was that |
Null is an allowed value according to the JSON spec, and it's what the Terraform docs say is expected behavior (encoding null results in null). To be honest, reading the issue I wondered if this was a case where "this is fixed by updating the docs" but it appears null is a valid case. If we look at other languages, So, I think this is the right move, and returning the string null would be less correct that returning null. |
It doesn't seem right to me that we're returning a In this case, I think that means For example, for JavaScript:
Python:
Ruby:
All of these are strings. |
@alisdair Thanks! Your comment helped me understand what I imagine was Martin's suggestion. I've committed an update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks right to me!
Ahh yes, sorry... that was indeed what I was meaning to say. Sorry for being unclear! 😖 This looks great, and I'm going to merge it now. |
This addresses hashicorp/terraform#23062, where
jsonencode
does not allow null values, but it is documented in Terraform that it does: https://www.terraform.io/docs/configuration/functions/jsonencode.html.Terraform currently uses this zclconf edition of the go-cty library, but if this change is unwarranted here, perhaps it would be a better fit to migrate Terraform to https://github.com/hashicorp/go-cty and make changes there.