mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Fixed empty array json bug #1880
This commit is contained in:
parent
1cf9ecc79d
commit
26effddb8c
@ -162,8 +162,13 @@ func (o *CandidateNode) MarshalJSON() ([]byte, error) {
|
||||
buf.WriteByte('}')
|
||||
return buf.Bytes(), nil
|
||||
case SequenceNode:
|
||||
log.Debugf("MarshalJSON SequenceNode")
|
||||
err := enc.Encode(o.Content)
|
||||
log.Debugf("MarshalJSON SequenceNode, %v, len: %v", o.Content, len(o.Content))
|
||||
var err error
|
||||
if len(o.Content) == 0 {
|
||||
buf.WriteString("[]")
|
||||
} else {
|
||||
err = enc.Encode(o.Content)
|
||||
}
|
||||
return buf.Bytes(), err
|
||||
default:
|
||||
err := enc.Encode(nil)
|
||||
|
@ -80,6 +80,27 @@ const roundTripMultiLineJson = `{
|
||||
`
|
||||
|
||||
var jsonScenarios = []formatScenario{
|
||||
{
|
||||
description: "array empty",
|
||||
skipDoc: true,
|
||||
input: "[]",
|
||||
scenarioType: "roundtrip-ndjson",
|
||||
expected: "[]\n",
|
||||
},
|
||||
{
|
||||
description: "array has scalar",
|
||||
skipDoc: true,
|
||||
input: "[3]",
|
||||
scenarioType: "roundtrip-ndjson",
|
||||
expected: "[3]\n",
|
||||
},
|
||||
{
|
||||
description: "array has object",
|
||||
skipDoc: true,
|
||||
input: `[{"x": 3}]`,
|
||||
scenarioType: "roundtrip-ndjson",
|
||||
expected: "[{\"x\":3}]\n",
|
||||
},
|
||||
{
|
||||
description: "array null",
|
||||
skipDoc: true,
|
||||
|
Loading…
Reference in New Issue
Block a user