Json Parse Data [unexecpted non whitespace 1 to 28]

122 views
Skip to first unread message

Ali Hassan

unread,
Apr 28, 2020, 4:53:38 AM4/28/20
to golang-nuts

Capture.JPG

Data : TYPE OF Json



var member Member // struct where json
data
, err :=json.Marshall(member); if err != nil{ fmt.Printf("Error %s",err)}
fmt
.Printf("Data", data)

err
= json.NewDecoder(request.Body).Decode(&member); if err != nil {fmt.Printf("Error %s",err) // this is print "EOF"}

unexpected non whitespaceing json parse data 1 to  colummn 28 



Brian Candler

unread,
Apr 28, 2020, 6:37:03 AM4/28/20
to golang-nuts
Can you make this into a standalone reproducing test case on play.golang.org, then share the URL with us?

Ali Hassan

unread,
Apr 28, 2020, 10:55:14 AM4/28/20
to golang-nuts
I try

Ali Hassan

unread,
Apr 28, 2020, 12:34:21 PM4/28/20
to golang-nuts


On Tuesday, April 28, 2020 at 1:53:38 PM UTC+5, Ali Hassan wrote:

Matthew Zimmerman

unread,
Apr 28, 2020, 1:15:44 PM4/28/20
to Ali Hassan, golang-nuts
Ali, that demo doesn't run given there's no http environment in the playground.  I assume this issue is not HTTP specific.

Something more like this (obviously change your data where it doesn't parse what you want):

Also, please don't store or recreate password schemes.  If you must, at least use https://godoc.org/golang.org/x/crypto/bcrypt

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1cedee73-bbe3-471a-a3ea-927735b85cbd%40googlegroups.com.

Marcin Romaszewicz

unread,
Apr 28, 2020, 2:49:37 PM4/28/20
to Ali Hassan, golang-nuts
Ali, your example has several problems.

First, you do this:

var p Person
data, err := json.Marshal(p); if err != nil{
fmt.Println("Error", err)
}

What this does is encode an empty object, that's fine.

Next, you read the HTTP body from the request, and try to unmarshal that.

fmt.Println("Data", data)
err = json.NewDecoder(r.Body).Decode(&p);if err != nil{
fmt.Println("Error2", err)
return
}

We have no idea what you're sending. If you are issuing a GET, there will be no reasonable body, and the JSON parser will correctly tell you that there is no data. Did you mean to initialize NewDecoder with "data"? If you do so, your example works.

In order for your code to work properly, you need to do an HTTP POST to /data on your handler with a JSON payload conforming to Person's schema.



--
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...@googlegroups.com.

Ali Hassan

unread,
Apr 29, 2020, 2:09:01 AM4/29/20
to golang-nuts


[Unexcepted NonWhitespacing json data parse after line 1 to 28 ] 

You can checkout my repo



On Tuesday, April 28, 2020 at 1:53:38 PM UTC+5, Ali Hassan wrote:

Brian Candler

unread,
Apr 29, 2020, 4:27:24 AM4/29/20
to golang-nuts
You have a specific piece of input data which is causing this error "json data parse after line 1 to 28"

Therefore, please modify your code to print the actual value just before parsing it; then do whatever triggers the error; then place that value inside the play.golang.org program to replicate the problem.

The JSON parser is saying that it's bad data, and so we want to see the exact data which cause the JSON parser to return this error.
Reply all
Reply to author
Forward
0 new messages