mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Fix JSON encoding removing null #985
This commit is contained in:
parent
2b3d0552a6
commit
08fc058934
@ -211,7 +211,8 @@ func (o *orderedMap) UnmarshalYAML(node *yaml.Node) error {
|
||||
}
|
||||
return nil
|
||||
case yaml.SequenceNode:
|
||||
var res []orderedMap
|
||||
// note that this has to be a pointer, so that nulls can be represented.
|
||||
var res []*orderedMap
|
||||
if err := node.Decode(&res); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -48,6 +48,24 @@ banana:
|
||||
test.AssertResult(t, expectedJson, actualJson)
|
||||
}
|
||||
|
||||
func TestJsonNullInArray(t *testing.T) {
|
||||
var sampleYaml = `[null]`
|
||||
var actualJson = yamlToJson(sampleYaml, 0)
|
||||
test.AssertResult(t, sampleYaml, actualJson)
|
||||
}
|
||||
|
||||
func TestJsonNull(t *testing.T) {
|
||||
var sampleYaml = `null`
|
||||
var actualJson = yamlToJson(sampleYaml, 0)
|
||||
test.AssertResult(t, sampleYaml, actualJson)
|
||||
}
|
||||
|
||||
func TestJsonNullInObject(t *testing.T) {
|
||||
var sampleYaml = `{x: null}`
|
||||
var actualJson = yamlToJson(sampleYaml, 0)
|
||||
test.AssertResult(t, `{"x":null}`, actualJson)
|
||||
}
|
||||
|
||||
func TestJsonEncoderDoesNotEscapeHTMLChars(t *testing.T) {
|
||||
var sampleYaml = `build: "( ./lint && ./format && ./compile ) < src.code"`
|
||||
var expectedJson = `{"build":"( ./lint && ./format && ./compile ) < src.code"}`
|
||||
|
Loading…
Reference in New Issue
Block a user