encoding/json: fix JSON import for numeric keys

Fixes #219.

Change-Id: I2a4093d37f660562d9993a9994d52ebad15f9214
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4361
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/encoding/json/json.go b/encoding/json/json.go
index e273686..db87de5 100644
--- a/encoding/json/json.go
+++ b/encoding/json/json.go
@@ -218,8 +218,8 @@
 					break // should not happen: implies invalid JSON
 				}
 
-				if q, err := ast.QuoteIdent(u); err != nil || q != u {
-					break
+				if !ast.IsValidIdent(u) {
+					break // keep string
 				}
 
 				x.Label = ast.NewIdent(u)
diff --git a/encoding/json/json_test.go b/encoding/json/json_test.go
index 6c33dc2..853e654 100644
--- a/encoding/json/json_test.go
+++ b/encoding/json/json_test.go
@@ -104,6 +104,10 @@
 		name: "invalid JSON",
 		in:   `[3_]`,
 		out:  "invalid JSON for file \"invalid JSON\": invalid character '_' after array element",
+	}, {
+		name: "numeric keys: Issue #219",
+		in:   `{"20": "a"}`,
+		out:  `{"20": "a"}`,
 	}}
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {