mikefarah/yq · error

node at path [%v] is not an array (it's a %v)

Error message

node at path [%v] is not an array (it's a %v)

What it means

The shuffle operator iterates matched nodes and requires each to be a SequenceNode — it applies a Fisher-Yates style reshuffle of array elements using math/rand. On the first non-array node it errors, printing the node's path and its actual tag (e.g. !!map or !!str).

Source

Thrown at pkg/yqlib/operator_shuffle.go:22

	"container/list"
	"fmt"
	"math/rand"
)

func shuffleOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {

	// ignore CWE-338 gosec issue of not using crypto/rand
	// this is just to shuffle an array rather generating a
	// secret or something that needs proper rand.
	myRand := rand.New(rand.NewSource(Now().UnixNano())) // #nosec

	results := list.New()

	for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
		candidate := el.Value.(*CandidateNode)

		if candidate.Kind != SequenceNode {
			return context, fmt.Errorf("node at path [%v] is not an array (it's a %v)", candidate.GetNicePath(), candidate.Tag)
		}

		result := candidate.Copy()

		a := result.Content

		myRand.Shuffle(len(a), func(i, j int) {
			a[i], a[j] = a[j], a[i]
			oldIndex := a[i].Key.Value
			a[i].Key.Value = a[j].Key.Value
			a[j].Key.Value = oldIndex
		})

		results.PushBack(result)
	}
	return context.ChildContext(results), nil
}

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Apply shuffle only to arrays: .items | shuffle
  2. Wrap scalars: [.] | shuffle
  3. Verify the field is a list and not null before shuffling
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pkg/yqlib/operator_shuffle.go:22 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05). Data as JSON: /api/errors/88c233579aeb000d. Report an issue: GitHub.