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

Add field to array of object. #68

Open
sujit-baniya opened this issue Apr 22, 2023 · 0 comments
Open

Add field to array of object. #68

sujit-baniya opened this issue Apr 22, 2023 · 0 comments

Comments

@sujit-baniya
Copy link

Is it possible to add field in array of object.

package main

import (
	"fmt"

	"github.com/tidwall/sjson"
)

func main() {
	jsondata1 := `{"data":[{"age": 30}, {"age": 35}, {"age": 40}]}`
	jsondata1, _ = sjson.Set(jsondata1, "data.[].name", "test")
	println(jsondata1)
}

Expected Result

{"data":[{"age": 30, "name": "test"}, {"age": 35, "name": "test"}, {"age": 40, "name": "test"}]}
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

1 participant