0

I'm trying to marshal to JSON a struct Foo that has a Values map[string]CellValue property where CellValue is another struct. For some reason, the resultant JSON does not contain the data held in the CellValue struct even though all the keys in the Values map are present.

Here's a simple playground repro of the issue.

I'm new to Go, can anyone spot the problem here?

jandersen
  • 3,551
  • 22
  • 23

1 Answers1

1

The fields of CellValue are unexported (start with a lowercase character). Per the documentation (emphasis mine), "Each exported struct field becomes a member of the object" - meaning unexported values are ignored when marshaling or unmarshaling.

Adrian
  • 42,911
  • 6
  • 107
  • 99
  • Doh! Absolutely right... this works: https://play.golang.org/p/-99s0wq8FK I can't accept as answer just yet but will after 10 minutes – jandersen Jun 08 '17 at 21:40