~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to src/pkg/json/encode.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
// Array and slice values encode as JSON arrays, except that
37
37
// []byte encodes as a base64-encoded string.
38
38
//
39
 
// Struct values encode as JSON objects.  Each struct field becomes
40
 
// a member of the object.  By default the object's key name is the
41
 
// struct field name.  If the struct field has a non-empty tag consisting
42
 
// of only Unicode letters, digits, and underscores, that tag will be used
43
 
// as the name instead.  Only exported fields will be encoded.
 
39
// Struct values encode as JSON objects.  Each exported struct field
 
40
// becomes a member of the object.  By default the object's key string
 
41
// is the struct field name.  If the struct field's tag has a "json" key with a
 
42
// value that is a non-empty string consisting of only Unicode letters,
 
43
// digits, and underscores, that value will be used as the object key.
 
44
// For example, the field tag `json:"myName"` says to use "myName"
 
45
// as the object key.
44
46
//
45
47
// Map values encode as JSON objects.
46
48
// The map's key type must be string; the object keys are used directly
236
238
                        } else {
237
239
                                e.WriteByte(',')
238
240
                        }
239
 
                        if isValidTag(f.Tag) {
240
 
                                e.string(f.Tag)
 
241
                        if tag := f.Tag.Get("json"); tag != "" && isValidTag(tag) {
 
242
                                e.string(tag)
241
243
                        } else {
242
244
                                e.string(f.Name)
243
245
                        }