mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-06 10:04:43 +08:00
Added get key examples
This commit is contained in:
@@ -13,6 +13,14 @@ var pathOperatorScenarios = []expressionScenario{
|
||||
"D0, P[a b], (!!seq)::- a\n- b\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Get map key",
|
||||
document: `{a: {b: cat}}`,
|
||||
expression: `.a.b | path | .[-1]`,
|
||||
expected: []string{
|
||||
"D0, P[a b -1], (!!str)::b\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Array path",
|
||||
document: `{a: [cat, dog]}`,
|
||||
@@ -21,6 +29,14 @@ var pathOperatorScenarios = []expressionScenario{
|
||||
"D0, P[a 1], (!!seq)::- a\n- 1\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Get array index",
|
||||
document: `{a: [cat, dog]}`,
|
||||
expression: `.a.[] | select(. == "dog") | path | .[-1]`,
|
||||
expected: []string{
|
||||
"D0, P[a 1 -1], (!!int)::1\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Print path and value",
|
||||
document: `{a: [cat, dog, frog]}`,
|
||||
|
||||
Reference in New Issue
Block a user