Skip to content

Commit 220ab10

Browse files
committed
Fix JSON compact output escape character issue
Fix issue with the incorrect escape character analog to default JSON output.
1 parent fce4fdf commit 220ab10

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

output_json.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ func (p *OutputProcessor) ToCompactJSON(obj interface{}) (string, error) {
9595
return fmt.Sprintf("[%s]", strings.Join(tmp, ", ")), nil
9696

9797
case yamlv3.ScalarNode:
98-
switch tobj.Tag {
99-
case "!!int", "!!float", "!!null", "!!bool":
100-
return tobj.Value, nil
98+
obj, err := cast(*tobj)
99+
if err != nil {
100+
return "", err
101+
}
101102

103+
bytes, err := json.Marshal(obj)
104+
if err != nil {
105+
return "", err
102106
}
103107

104-
return fmt.Sprintf("\"%s\"", tobj.Value), nil
108+
return string(bytes), nil
105109
}
106110

107111
case []interface{}:

0 commit comments

Comments
 (0)