mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-06 10:04:43 +08:00
Added custom sort map example
This commit is contained in:
@@ -52,6 +52,15 @@ var entriesOperatorScenarios = []expressionScenario{
|
||||
"D0, P[], (!!map)::KEY_a: 1\nKEY_b: 2\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Custom sort map keys",
|
||||
subdescription: "Use to_entries to convert to an array of key/value pairs, sort the array using sort/sort_by/etc, and convert it back.",
|
||||
document: `{a: 1, c: 3, b: 2}`,
|
||||
expression: `to_entries | sort_by(.key) | reverse | from_entries`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!map)::c: 3\nb: 2\na: 1\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{a: 1, b: 2}`,
|
||||
|
||||
Reference in New Issue
Block a user