AW: [go-nuts] MarshalJSON() output encrypted json

2019-12-27 Thread Lutz Horn
ts@googlegroups.com> Betreff: [go-nuts] MarshalJSON() output encrypted json https://play.golang.org/p/6qKkJhVsnU1 type Payload struct{} func (p Payload) MarshalJSON() ([]byte, error) { return []byte("my custom encryption stuf"), nil } func main() { p := Payload{} j, err := json.Marsha

Re: [go-nuts] MarshalJSON() output encrypted json

2019-12-27 Thread Dan Kortschak
It depends what you want to get. json.Marshal picks up encoding.TextEncoder and Unmarshal, TextDecoder. It will wrap the marshaled text into a quoted json string and then pull it out again when you deserialise. From the json.Marshal docs ``` If no MarshalJSON method is present but the value

Re: [go-nuts] MarshalJSON() output encrypted json

2019-12-27 Thread Gert Cuykens
Ok thanks, I will try that but don't think it will be elegant for turning on and off plain json in a code base, because I have to change every json.Marshal and json.Umarshal On Fri, Dec 27, 2019 at 10:21 AM Dan Kortschak wrote: > > MarshalText? > > On Fri, 2019-12-27 at 09:51 +0100, Gert Cuykens

Re: [go-nuts] MarshalJSON() output encrypted json

2019-12-27 Thread Dan Kortschak
MarshalText? On Fri, 2019-12-27 at 09:51 +0100, Gert Cuykens wrote: > Thanks, Which should I use instead then? The reason I use it is so I > can easily switch between regular json payloads for debugging and > encrypted/signed urlencode payloads > > On Fri, Dec 27, 2019 at 9:39 AM Axel Wagner >

Re: [go-nuts] MarshalJSON() output encrypted json

2019-12-27 Thread Gert Cuykens
Thanks, Which should I use instead then? The reason I use it is so I can easily switch between regular json payloads for debugging and encrypted/signed urlencode payloads On Fri, Dec 27, 2019 at 9:39 AM Axel Wagner wrote: > > `MarshalJSON` needs to output a valid JSON value, according to the

Re: [go-nuts] MarshalJSON() output encrypted json

2019-12-27 Thread 'Axel Wagner' via golang-nuts
`MarshalJSON` needs to output a valid JSON value, according to the interface . If you don't need the result to be valid JSON, then don't use encoding/json. If you want to use JSON to use it as part of a larger value, you could output a JSON string

[go-nuts] MarshalJSON() output encrypted json

2019-12-26 Thread Gert
https://play.golang.org/p/6qKkJhVsnU1 type Payload struct{} func (p Payload) MarshalJSON() ([]byte, error) { return []byte("my custom encryption stuf"), nil } func main() { p := Payload{} j, err := json.Marshal(p) if err != nil { fmt.Println(err) } fmt.Println(string(j)) } json: error calling