On Tue, Dec 29, 2020 at 9:50 PM Axel Wagner
<[email protected]> wrote:
>
> There is an important semantic difference between the two, which means you 
> almost never want to use a `Decoder`: `Unmarshal` is for parsing a single 
> json document, whereas a `Decoder` is for parsing a stream of concatenated 
> documents, like so: https://play.golang.org/p/4uiNyJlNIKh. In particular, 
> this means that using a `Decoder` silently drops trailing data and might not 
> detect erronous json: https://play.golang.org/p/cuOAUnKCuEk
> So, unless you specifically know that you have a stream of concatenated json 
> documents `Decoder` is not actually doing what you want.

Indeed, thank you for the explanation.

>
> On Tue, Dec 29, 2020 at 11:37 AM Amit Saha <[email protected]> wrote:
>>
>> On Tue, Dec 29, 2020 at 11:35 AM burak serdar <[email protected]> wrote:
>> >
>> > On Mon, Dec 28, 2020 at 5:22 PM Amit Saha <[email protected]> wrote:
>> > >
>> > > Hi all, let's say I am a single large JSON object that I want to
>> > > process in my HTTP server backend.
>> > >
>> > > I am trying to get my head around if there is any performance
>> > > advantage - memory or CPU to use the json.NewDecoder()/Decode()
>> > > mechanism versus the Unmarshal() function?
>> >
>> > Unmarshal uses the decoder for unmarshaling. Unless you are planning
>> > to process the JSON object piece by piece using a decoder, the two are
>> > identical in terms of performance.
>>
>> Thank you for confirming.
>>
>>
>> >
>> > >
>> > > Thanks,
>> > > Amit
>> > >
>> > > --
>> > > You received this message because you are subscribed to the Google 
>> > > Groups "golang-nuts" group.
>> > > To unsubscribe from this group and stop receiving emails from it, send 
>> > > an email to [email protected].
>> > > To view this discussion on the web visit 
>> > > https://groups.google.com/d/msgid/golang-nuts/CANODV3%3DU2KRRkvAAEfYqRtCVtYnh2dmGreqePF8QXLo1PriSPw%40mail.gmail.com.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/CANODV3%3DpXGcHzhSmaLr3f911i2CCYb0_j8CGH7zKAZXd_xTD-A%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANODV3mFGGetoijZAXzrw9QLEji1asH1eWZbkVn8-TymVsTOOw%40mail.gmail.com.

Reply via email to