mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-14 07:08:06 +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('}')
|
buf.WriteByte('}')
|
||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
case SequenceNode:
|
case SequenceNode:
|
||||||
log.Debugf("MarshalJSON SequenceNode")
|
log.Debugf("MarshalJSON SequenceNode, %v, len: %v", o.Content, len(o.Content))
|
||||||
err := enc.Encode(o.Content)
|
var err error
|
||||||
|
if len(o.Content) == 0 {
|
||||||
|
buf.WriteString("[]")
|
||||||
|
} else {
|
||||||
|
err = enc.Encode(o.Content)
|
||||||
|
}
|
||||||
return buf.Bytes(), err
|
return buf.Bytes(), err
|
||||||
default:
|
default:
|
||||||
err := enc.Encode(nil)
|
err := enc.Encode(nil)
|
||||||
|
@ -80,6 +80,27 @@ const roundTripMultiLineJson = `{
|
|||||||
`
|
`
|
||||||
|
|
||||||
var jsonScenarios = []formatScenario{
|
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",
|
description: "array null",
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user