jsonparser icon indicating copy to clipboard operation
jsonparser copied to clipboard

Set() doesnt return a normal json data

Open improvisor40 opened this issue 1 year ago • 0 comments

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!!.

improvisor40 avatar Mar 15 '24 05:03 improvisor40