Skip to content

Commit b56e5cf

Browse files
bbasataapparentlymartpselle
authored
Forward to v1.4.2 (#8)
* Prepare CHANGELOG for a forthcoming 1.4.2 release * function/stdlib: jsonencode should produce a string representation of null * Update CHANGELOG.md * v1.4.2 release * Update CHANGELOG.md --------- Co-authored-by: Martin Atkins <[email protected]> Co-authored-by: Pam Selle <[email protected]>
1 parent 016615a commit b56e5cf

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 1.4.2 (Unreleased)
22

3+
* `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))
34
* `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))
45

56
# 1.4.1 (March 5, 2025)

cty/function/stdlib/json.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var JSONEncodeFunc = function.New(&function.Spec{
1212
Name: "val",
1313
Type: cty.DynamicPseudoType,
1414
AllowDynamicType: true,
15+
AllowNull: true,
1516
},
1617
},
1718
Type: function.StaticReturnType(cty.String),
@@ -24,6 +25,10 @@ var JSONEncodeFunc = function.New(&function.Spec{
2425
return cty.UnknownVal(retType), nil
2526
}
2627

28+
if val.IsNull() {
29+
return cty.StringVal("null"), nil
30+
}
31+
2732
buf, err := json.Marshal(val, val.Type())
2833
if err != nil {
2934
return cty.NilVal, err

cty/function/stdlib/json_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func TestJSONEncode(t *testing.T) {
5252
cty.DynamicVal,
5353
cty.UnknownVal(cty.String),
5454
},
55+
{
56+
cty.NullVal(cty.String),
57+
cty.StringVal("null"),
58+
},
5559
}
5660

5761
for _, test := range tests {

0 commit comments

Comments
 (0)