Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't this scenario assign a value to a list? #58

Open
jianghaodong-icel opened this issue Jun 7, 2022 · 1 comment
Open

Why can't this scenario assign a value to a list? #58

jianghaodong-icel opened this issue Jun 7, 2022 · 1 comment

Comments

@jianghaodong-icel
Copy link

type StudentInfo struct {
	StudentId string   `json:"student_id"`
	Class     []string `json:"class"`
}

type Item struct {
	StudentInfo []*StudentInfo `json:"student_info"`
}

func main() {
	item := &Item{
		[]*StudentInfo{
			{
				StudentId: "1",
				Class:     []string{"class1"},
			},
		},
	}
	itemBytes, _ := json.Marshal(item)
	ret, _ := sjson.Set(string(itemBytes), `student_info.#(student_id=="1").class.-1`, "class2")
	fmt.Println(ret)
}

my desired result is {"student_info":[{"student_id":"1","class":["class1","class2"]}]},but the actual result is {"student_info":[{"student_id":"1","class":["class1"]}]}

@momoadc
Copy link

momoadc commented Feb 22, 2023

I'm dealing with the same problem. Did you manage to solve it? @jianghaodong-icel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants