Skip to content

Set with index overrides always first position of the array  #267

Description

@fedeizzo

What is the problem

If I try to call Set on an array jsonparser always replaces the first element of the array, regardless of the index passed

How to replicate

	myJSON := []byte(`{}`)
	myJSON, _ = jsonparser.Set(myJSON, []byte("1"), "test", "[0]")
	myJSON, _ = jsonparser.Set(myJSON, []byte("2"), "test", "[1]")
	myJSON, _ = jsonparser.Set(myJSON, []byte("3"), "test", "[2]")

	fmt.Println(string(myJSON))

Expected output

{"test":[1,2,3]}

Actual output

{"test":[3]}

Activity

  1. buger commented on Jul 28, 2026

    @buger
    Owner

    Fixed in v1.3.0 — Set on array-index beyond length now appends instead of overwriting. See SYS-REQ-110 and the regression tests in set_spec_test.go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions