From 37f8e1839bfe4edac197ac0a74b4f06af9e585a7 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Mon, 18 May 2020 10:24:16 -0700 Subject: [PATCH 1/5] Prepare CHANGELOG for a forthcoming 1.4.2 release From fd0750a700a741940d1c6b9058b86e0a8f89f438 Mon Sep 17 00:00:00 2001 From: Pam Selle Date: Thu, 28 May 2020 13:50:09 -0400 Subject: [PATCH 2/5] function/stdlib: jsonencode should produce a string representation of null --- cty/function/stdlib/json.go | 5 +++++ cty/function/stdlib/json_test.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/cty/function/stdlib/json.go b/cty/function/stdlib/json.go index 8ae70f35..21f84565 100644 --- a/cty/function/stdlib/json.go +++ b/cty/function/stdlib/json.go @@ -12,6 +12,7 @@ var JSONEncodeFunc = function.New(&function.Spec{ Name: "val", Type: cty.DynamicPseudoType, AllowDynamicType: true, + AllowNull: true, }, }, Type: function.StaticReturnType(cty.String), @@ -24,6 +25,10 @@ var JSONEncodeFunc = function.New(&function.Spec{ return cty.UnknownVal(retType), nil } + if val.IsNull() { + return cty.StringVal("null"), nil + } + buf, err := json.Marshal(val, val.Type()) if err != nil { return cty.NilVal, err diff --git a/cty/function/stdlib/json_test.go b/cty/function/stdlib/json_test.go index 3ebdc9a8..45fead09 100644 --- a/cty/function/stdlib/json_test.go +++ b/cty/function/stdlib/json_test.go @@ -52,6 +52,10 @@ func TestJSONEncode(t *testing.T) { cty.DynamicVal, cty.UnknownVal(cty.String), }, + { + cty.NullVal(cty.String), + cty.StringVal("null"), + }, } for _, test := range tests { From ef8eed7f6592ed6f797eb614027bd394636b9c5a Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 28 May 2020 10:52:44 -0700 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85de6ef6..ac175df4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 1.4.2 (Unreleased) +* `function/stdlib`: The `jsonencode` function will now correctly accept a null as its argument, and produce the JSON representation `"null"` rather than returning an error. ([#54](https://github.com/zclconf/go-cty/pull/54)) * `convert`: Don't panic when asked to convert a tuple of objects to a list type constraint containing a nested `cty.DynamicPseudoType`. ([#53](https://github.com/zclconf/go-cty/pull/53)) # 1.4.1 (March 5, 2025) From a52c9032108f78e15c685b52762c8c50e1fe1682 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 29 May 2020 09:40:57 -0700 Subject: [PATCH 4/5] v1.4.2 release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac175df4..26ebf56e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.4.2 (Unreleased) +# 1.4.2 (May 29, 2020) * `function/stdlib`: The `jsonencode` function will now correctly accept a null as its argument, and produce the JSON representation `"null"` rather than returning an error. ([#54](https://github.com/zclconf/go-cty/pull/54)) * `convert`: Don't panic when asked to convert a tuple of objects to a list type constraint containing a nested `cty.DynamicPseudoType`. ([#53](https://github.com/zclconf/go-cty/pull/53)) From 79dc5e902bbea20e7b0e227a217f04f374637f94 Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Thu, 6 Mar 2025 09:42:34 -0500 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26ebf56e..ac175df4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.4.2 (May 29, 2020) +# 1.4.2 (Unreleased) * `function/stdlib`: The `jsonencode` function will now correctly accept a null as its argument, and produce the JSON representation `"null"` rather than returning an error. ([#54](https://github.com/zclconf/go-cty/pull/54)) * `convert`: Don't panic when asked to convert a tuple of objects to a list type constraint containing a nested `cty.DynamicPseudoType`. ([#53](https://github.com/zclconf/go-cty/pull/53))