The Json Golang doc <https://golang.org/pkg/encoding/json/> indicates that 
"Package json implements encoding and decoding of JSON as defined in RFC 
4627 <https://tools.ietf.org/html/rfc4627>". 

It's a deprecated RFC, and, contrary to the most recent you spoke about, It 
says nothing about truncated/invalid json.
It explains why the package doesn't provide such feature I guess !

Maybe, should I report as feature proposal to update the package for most 
recent RFC ?

Thank you

Le vendredi 20 janvier 2017 15:44:59 UTC+1, Jordan Krage a écrit :
>
> Robustness brings complexity here.
>>
> Relevant: RFC7464 - JavaScript Object Notation (JSON) Text Sequences 
> <https://tools.ietf.org/html/rfc7464>
>
> Given that format, it should be possible to parse record boundaries 
> reliably, and then use the std lib to unmarshal them individually.
>
> On Friday, January 20, 2017 at 3:54:21 AM UTC-6, Thomas Solignac wrote:
>>
>>
>> Thank you both for your answers.
>>
>> It's true that there is a convention for JSON streaming in which one each 
>> json message is followed by a '\n'.
>>
>> There is + and - for this convention.
>>
>> *+ :*
>> -> I can detect bad JSON
>>
>> *- :*
>> -> The most important : It's a little more painful for final user. It's 
>> already rare to have a WS connection rather than HTTP, I'm not confortable 
>> with the idea tu push forward the first impression of weirdness.
>> -> Secondly, I can't use standard decoder package anymore for this. I 
>> need an other package, or do it my self. But the parsing is not trivial, as 
>> I can get '\n' or Json reserved character inside a string. Robustness 
>> brings complexity here.
>>
>>
>> However, such different answers let me get an accurate synthesis.
>> This allows me to make a decision :
>>
>> I'm going to stay on the actual convention, with the standard decoder.
>>
>> I added a new error message, indicating that the JSON message is not 
>> valid.
>> And I'm trying now to get that bad formatted message for more explicit 
>> error. (Maybe read directly the socket ? Let's set)
>>
>>
>> Thank you for this enlightening discussion !
>>
>>
>>
>>
>> Le jeudi 19 janvier 2017 22:43:13 UTC+1, nost...@gmail.com a écrit :
>>>
>>> A partial stream must still be a valid stream. Once the stream is in an 
>>> invalid state, the decoder doesn't know how to proceed. Since none of the 
>>> value types that can be represented by JSON can begin with the letter "T", 
>>> the stream can be considered invalid soon as the decoder encounters that 
>>> character. 
>>>
>>> There are some methods for JSON communication that define a way to have 
>>> separate chunks within a stream. A common one is a stream that has 
>>> individual JSON values separated by new lines. If you were implementing 
>>> such a stream, a valid response might be to continue reading until you 
>>> reach the next new line, and then attempt to start a new decode from there. 
>>
>>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to