# Json Decode Issue

**URL:** <https://forum.golangbridge.org/t/json-decode-issue/4258>\
**Category:** Getting Help\
**Created:** [January 3, 2017, 2:21pm UTC](https://forum.golangbridge.org/t/json-decode-issue/4258 "2017-01-03T14:21:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nirmal\_Singh](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@Nirmal\_Singh](https://forum.golangbridge.org/u/Nirmal_Singh)\
**Post date:** [January 3, 2017, 2:21pm UTC](https://forum.golangbridge.org/t/json-decode-issue/4258/1 "2017-01-03T14:21:36Z")

</div>

Hi,

I am using the below code to decode the json which I have hardcoded in the code but when I am trying to decode that I m not getting the all [values.As](http://values.As) I have mentioned the output of that code [below.So](http://below.So) please let me know is there any other way to decode this type of json and getting all key’s values.

package main

import (  
“fmt”  
“encoding/json”  
)

type LogEntry struct {  
filename string  
functionname string  
level int  
LineNo int  
msg string  
time string  
}

func main() {

```
var c LogEntry
result := `{"filename":"caches.go","functionname":"updateCaches","level":"info","lineno":31,"msg":"updating Caches","time":"2017-01-03T18:37:34+05:30"}`
err:=json.Unmarshal([]byte(result), &c)

	if err!=nil{
		fmt.Println("here is error",err)
		
	}else{
		fmt.Println("here is no error",c)
	}

```

}

Output :

here is no error { 0 31 }

---

<div class="post-metadata">

**Author:** ![ericmdantas](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/ericmdantas/32/1001_2.png) [@ericmdantas](https://forum.golangbridge.org/u/ericmdantas)\
**Post date:** [January 3, 2017, 2:36pm UTC](https://forum.golangbridge.org/t/json-decode-issue/4258/2 "2017-01-03T14:36:34Z")

</div>

Hello, @Nirmal_Singh.

You should use the `json` notation in the struct, as follows:

```auto
type LogEntry struct {
  Filename string `json:"filename"`
  Functionname string `json:"functionname"`
  Level string `json:"level"`
  LineNo int `json:"lineno"`
  Msg string `json:"msg"`
  Time string `json:"time"`
}

```

Note: the field should start with a capital letter  
Note2: Level is a string, not int

Edit1: Identation  
Edit2: Level type is string

---

<div class="post-metadata">

**Author:** ![dfc](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/dfc/32/53_2.png) [@dfc](https://forum.golangbridge.org/u/dfc)\
**Post date:** [January 3, 2017, 2:39pm UTC](https://forum.golangbridge.org/t/json-decode-issue/4258/3 "2017-01-03T14:39:00Z")

</div>

Structs must have exported fields for the reflect package, used by encoding/json, to read and set them.

Try this

```auto
type LogEntry struct {
        Filename string `json:"filename"`
        Functionname string `json:"functionname"`
        Level int `json:"level"`
        LineNo int `json:"lineno"`
        Msg string `json:"msg"`
        Time string `json:"time"`
}
```

---

<div class="post-metadata">

**Author:** ![dweidenfeld](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/dweidenfeld/32/2315_2.png) [@dweidenfeld](https://forum.golangbridge.org/u/dweidenfeld)\
**Post date:** [January 3, 2017, 2:40pm UTC](https://forum.golangbridge.org/t/json-decode-issue/4258/4 "2017-01-03T14:40:21Z")

</div>

Exactly, I was just a bit too late:

Here the working example: [https://play.golang.org/p/Eo5qS0nHAH](https://play.golang.org/p/Eo5qS0nHAH)

---

<div class="post-metadata">

**Author:** ![Nirmal\_Singh](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@Nirmal\_Singh](https://forum.golangbridge.org/u/Nirmal_Singh)\
**Post date:** [January 4, 2017, 7:16am UTC](https://forum.golangbridge.org/t/json-decode-issue/4258/5 "2017-01-04T07:16:17Z")

</div>

Thank you so much!

It really worked.

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [April 4, 2017, 7:16am UTC](https://forum.golangbridge.org/t/json-decode-issue/4258/6 "2017-04-04T07:16:25Z")

</div>

Closed on April 4, 2017, 7:16am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
