自己的结构体数组的JSON编码

I try to read a directory and make a JSON string out of the file entries. But the json.encoder.Encode() function returns only empty objects. For test I have two files in a tmp dir:

test1.js  test2.js 

The go program is this:

package main

import (
    "encoding/json"
    "fmt"
    "os"
    "path/filepath"
    "time"
)

type File struct {
    name      string
    timeStamp int64
}

func main() {

    files := make([]File, 0, 20)

    filepath.Walk("/home/michael/tmp/", func(path string, f os.FileInfo, err error) error {

        if f == nil {
            return nil
        }

        name := f.Name()
        if len(name) > 3 {
            files = append(files, File{
                name:      name,
                timeStamp: f.ModTime().UnixNano() / int64(time.Millisecond),
            })

            // grow array if needed
            if cap(files) == len(files) {
                newFiles := make([]File, len(files), cap(files)*2)
                for i := range files {
                    newFiles[i] = files[i]
                }
                files = newFiles
            }
        }
        return nil
    })

    fmt.Println(files)

    encoder := json.NewEncoder(os.Stdout)
    encoder.Encode(&files)
}

And the out that it produces is:

[{test1.js 1444549471481} {test2.js 1444549481017}]
[{},{}]

Why is the JSON string empty?

It doesn't work because none of the fields in the File struct are exported.

The following works just fine:

package main

import (
    "encoding/json"
    "fmt"
    "os"
    "path/filepath"
    "time"
)

type File struct {
    Name      string
    TimeStamp int64
}

func main() {

    files := make([]File, 0, 20)

    filepath.Walk("/tmp/", func(path string, f os.FileInfo, err error) error {

        if f == nil {
            return nil
        }

        name := f.Name()
        if len(name) > 3 {
            files = append(files, File{
                Name:      name,
                TimeStamp: f.ModTime().UnixNano() / int64(time.Millisecond),
            })

            // grow array if needed
            if cap(files) == len(files) {
                newFiles := make([]File, len(files), cap(files)*2)
                for i := range files {
                    newFiles[i] = files[i]
                }
                files = newFiles
            }
        }
        return nil
    })

    fmt.Println(files)
    encoder := json.NewEncoder(os.Stdout)
    encoder.Encode(&files)
}