sjson icon indicating copy to clipboard operation
sjson copied to clipboard

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

Open jianghaodong-icel opened this issue 2 years ago • 1 comments

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"]}]}

jianghaodong-icel avatar Jun 07 '22 15:06 jianghaodong-icel

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

momoadc avatar Feb 22 '23 14:02 momoadc