JSON Marshaling not outputting anything

Can anyone tell me why this isn’t working? I’ve cut down my code to a basic example. I’m trying to store several variables in a struct then write the whole struct out as JSON.

package main

import (

type DiskSpaceOutput struct {
	text string
	last_updated string

func main() {

	var JSONOutput DiskSpaceOutput
	JSONOutput.last_updated = fmt.Sprintf(time.Now().Format(time.RFC3339))
	JSONOutput.text = string("test")


	JSONOutputText, err := json.Marshal(JSONOutput)
	if err != nil {

The output I get is:

{} <nil>

Program exited.

I can’t see why the JSONOutputText is {} rather than showing the data in the struct in JSON format.

Link to the above code at go playground: https://play.golang.org/p/e2f7uArQ71I

JSON does not see I exported fields. You need to export them.

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