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

Set() doesnt return a normal json data #270

Open
improvisor40 opened this issue Mar 15, 2024 · 0 comments
Open

Set() doesnt return a normal json data #270

improvisor40 opened this issue Mar 15, 2024 · 0 comments

Comments

@improvisor40
Copy link

improvisor40 commented Mar 15, 2024

i have an implementation of jsonparser for marshaling/appending data to a json structure from a struct, but
anytime i use Set() it return a data type that is not json, but looks like a javascript object.
heres my code:

package main
import (
"github.com/buger/jsonparser"
"fmt"
)
type Layout struct {
One string `json:"one"`
}
//INCOMPLETE!!
func (l Layout) LayoutSerializer() []byte {
var ref []byte
ref = []byte(`{"one": "",`)
store,_ := jsonparser.Set(ref, []byte(l.One), "one")
return store
}
func main() {
d := Layout{One:"hello wrld",}
collect := d.LayoutSerializer()
fmt.Println(string(collect))
}
//outputs:
/*{"one": hello wrld,}*/
//instead of:
/* {"one":" hello wrld",} */

what is wrong here cause i cant parse this output as its not recognized as json data!!.

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