diff --git a/pkg/yqlib/doc/operators/entries.md b/pkg/yqlib/doc/operators/entries.md index 28d3ac41..a0593c7f 100644 --- a/pkg/yqlib/doc/operators/entries.md +++ b/pkg/yqlib/doc/operators/entries.md @@ -61,10 +61,8 @@ yq 'to_entries | from_entries' sample.yml ``` will output ```yaml -- a -- 1 -- b -- 2 +a: 1 +b: 2 ``` ## from_entries with numeric key indices @@ -80,10 +78,8 @@ yq 'to_entries | from_entries' sample.yml ``` will output ```yaml -- 0 -- a -- 1 -- b +0: a +1: b ``` ## Use with_entries to update keys @@ -97,10 +93,8 @@ yq 'with_entries(.key |= "KEY_" + .)' sample.yml ``` will output ```yaml -- KEY_a -- 1 -- KEY_b -- 2 +KEY_a: 1 +KEY_b: 2 ``` ## Custom sort map keys @@ -116,13 +110,9 @@ yq 'to_entries | sort_by(.key) | reverse | from_entries' sample.yml ``` will output ```yaml -!!tag -- c -- 3 -- b -- 2 -- a -- 1 +c: 3 +b: 2 +a: 1 ``` ## Use with_entries to filter the map @@ -136,7 +126,6 @@ yq 'with_entries(select(.value | has("b")))' sample.yml ``` will output ```yaml -- a -- {b: bird} +a: {b: bird} ``` diff --git a/pkg/yqlib/operator_entries.go b/pkg/yqlib/operator_entries.go index dd246358..6ee651cd 100644 --- a/pkg/yqlib/operator_entries.go +++ b/pkg/yqlib/operator_entries.go @@ -88,7 +88,7 @@ func parseEntry(candidateNode *CandidateNode, position int) (*CandidateNode, *Ca } func fromEntries(candidateNode *CandidateNode) (*CandidateNode, error) { - var node = candidateNode.CopyWithoutContent() + var node = candidateNode.unwrapDocument().CopyWithoutContent() var contents = candidateNode.unwrapDocument().Content @@ -100,6 +100,8 @@ func fromEntries(candidateNode *CandidateNode) (*CandidateNode, error) { node.Content = append(node.Content, key, value) } + node.Kind = MappingNode + node.Tag = "!!map" return node, nil }