Skip to content

Commit 3e6529d

Browse files
committed
encoding/json: revise docs for Unmarshal into map, slice, array
Fixes golang#12972. Change-Id: Id0611667e6149753c351c0c5e01211340a87d3fd Reviewed-on: https://go-review.googlesource.com/17230 Reviewed-by: David Crawshaw <[email protected]>
1 parent de5b386 commit 3e6529d

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/encoding/json/decode.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,22 @@ import (
4848
// map[string]interface{}, for JSON objects
4949
// nil for JSON null
5050
//
51-
// To unmarshal a JSON array into a slice, Unmarshal resets the slice to nil
52-
// and then appends each element to the slice.
51+
// To unmarshal a JSON array into a slice, Unmarshal resets the slice length
52+
// to zero and then appends each element to the slice.
53+
// As a special case, to unmarshal an empty JSON array into a slice,
54+
// Unmarshal replaces the slice with a new empty slice.
5355
//
54-
// To unmarshal a JSON object into a map, Unmarshal replaces the map
55-
// with an empty map and then adds key-value pairs from the object to
56-
// the map.
56+
// To unmarshal a JSON array into a Go array, Unmarshal decodes
57+
// JSON array elements into corresponding Go array elements.
58+
// If the Go array is smaller than the JSON array,
59+
// the additional JSON array elements are discarded.
60+
// If the JSON array is smaller than the Go array,
61+
// the additional Go array elements are set to zero values.
62+
//
63+
// To unmarshal a JSON object into a string-keyed map, Unmarshal first
64+
// establishes a map to use, If the map is nil, Unmarshal allocates a new map.
65+
// Otherwise Unmarshal reuses the existing map, keeping existing entries.
66+
// Unmarshal then stores key-value pairs from the JSON object into the map.
5767
//
5868
// If a JSON value is not appropriate for a given target type,
5969
// or if a JSON number overflows the target type, Unmarshal

0 commit comments

Comments
 (0)