Re: [Json] Go JSON parser ignores the case of member names
"Manger, James" <James.H.Manger@team.telstra.com> Thu, 10 March 2016 04:56 UTC
Return-Path: <James.H.Manger@team.telstra.com>
X-Original-To: json@ietfa.amsl.com
Delivered-To: json@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id D44D312DDB6 for <json@ietfa.amsl.com>; Wed, 9 Mar 2016 20:56:17 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.62
X-Spam-Level:
X-Spam-Status: No, score=-2.62 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NI-IzbMDfcAs for <json@ietfa.amsl.com>; Wed, 9 Mar 2016 20:56:15 -0800 (PST)
Received: from ipxano.tcif.telstra.com.au (ipxano.tcif.telstra.com.au [203.35.82.200]) by ietfa.amsl.com (Postfix) with ESMTP id DACD012DDB4 for <json@ietf.org>; Wed, 9 Mar 2016 20:56:13 -0800 (PST)
X-IronPort-AV: E=Sophos;i="5.24,314,1454936400"; d="scan'208";a="66998206"
Received: from unknown (HELO ipcani.tcif.telstra.com.au) ([10.97.216.200]) by ipoani.tcif.telstra.com.au with ESMTP; 10 Mar 2016 15:55:48 +1100
X-IronPort-AV: E=McAfee;i="5700,7163,8099"; a="85209405"
Received: from wsmsg3752.srv.dir.telstra.com ([172.49.40.173]) by ipcani.tcif.telstra.com.au with ESMTP; 10 Mar 2016 15:55:48 +1100
Received: from WSMSG3153V.srv.dir.telstra.com ([172.49.40.159]) by wsmsg3752.srv.dir.telstra.com ([fe80::91f4:aabc:bfb0:95c4%16]) with mapi; Thu, 10 Mar 2016 15:55:48 +1100
From: "Manger, James" <James.H.Manger@team.telstra.com>
To: John Cowan <cowan@mercury.ccil.org>, Rob Sayre <sayrer@gmail.com>
Date: Thu, 10 Mar 2016 15:55:47 +1100
Thread-Topic: [Json] Go JSON parser ignores the case of member names
Thread-Index: AdF6crTFfW+CeUxXQJieFaX8WfuMrQACYYiA
Message-ID: <255B9BB34FB7D647A506DC292726F6E13BBE7517EF@WSMSG3153V.srv.dir.telstra.com>
References: <255B9BB34FB7D647A506DC292726F6E13BBE5873A1@WSMSG3153V.srv.dir.telstra.com> <20160309012028.GQ32247@mercury.ccil.org> <CAChr6SyGoRO-CgH5cPSXLLhnqkd5kJb9XpJ-evgJ1kB=mUot9A@mail.gmail.com> <20160309213830.GB9515@mercury.ccil.org> <CAChr6SwdCcb=xd+K4J2tbDqKSmqWjEoO8DKhb1QrtG9KEo28rw@mail.gmail.com> <20160310021502.GD9515@mercury.ccil.org>
In-Reply-To: <20160310021502.GD9515@mercury.ccil.org>
Accept-Language: en-US, en-AU
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
acceptlanguage: en-US, en-AU
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Archived-At: <http://mailarchive.ietf.org/arch/msg/json/EzAIBImSMLZdDFIJBtj7Os97IlQ>
Cc: "json@ietf.org" <json@ietf.org>
Subject: Re: [Json] Go JSON parser ignores the case of member names
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.17
Precedence: list
List-Id: "JavaScript Object Notation \(JSON\) WG mailing list" <json.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/json>, <mailto:json-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/json/>
List-Post: <mailto:json@ietf.org>
List-Help: <mailto:json-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/json>, <mailto:json-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 10 Mar 2016 04:56:18 -0000
>> I understand the situation. I guess I don't agree there's a >> conformance problem here, since there are plenty of other APIs in the >> standard package that don't do this transformation, and even the API >> in question doesn't do this transformation for all arguments. They're >> right below the section James quoted. > Ah. I didn't know that. I am fairly new to Go so there is heaps I don't know. However, I don't think the case-insensitive transformation is quite as optional as Rob suggests. "encoding/json" looks like THE standard JSON package in Go. It can parse (Unmarshall) a JSON object into a Go map or struct. Parsing to a map (useful for handling unknown or arbitrary JSON) preserves the case of the object members. Parsing to a struct (ie object-mapping) ignores case - always. I cannot see any option NOT to ignore case when parsing to a struct. There is no equivalent of MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES. Object-mapping is a great developer convenience. However, it looks like the Go implementation is an "attractive nuisance" < https://en.wikipedia.org/wiki/Attractive_nuisance_doctrine>. Parsing to a struct is front and centre in the doco, yet comes with this risky case-ignoring transformation that cannot be disabled. >> BTW, here's how to get a similar effect using the widely-used Java library Jackson[0]: >> >> ObjectMapper objectMapper = new ObjectMapper(); >> objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); > Sure, but this is a feature you have to enable specifically, not the default. But from what you are saying, the Go case mapping is not the default either. > It's perfectly reasonable, given how much ill-formed or incorrect JSON there is, to have relaxed modes. It's just that the main mode should be strict. Go supports tags on struct fields (eg Algorithm string `json:"alg,omitempty"`). Supporting, say, an "ignorecase" option in the tag might have been a reasonable design. P.S. Another interesting feature of the standard JSON package in Go is that it ALWAYS escapes "<" as "\u003c" - as a safety feature, in case the JSON is used within HTML. This safety decision seems such a contrast to the decision to ALWAYS ignore case when parsing to a struct. -- James Manger
- [Json] Go JSON parser ignores the case of member … Manger, James
- Re: [Json] Go JSON parser ignores the case of mem… John Cowan
- Re: [Json] Go JSON parser ignores the case of mem… Rob Sayre
- Re: [Json] Go JSON parser ignores the case of mem… John Cowan
- Re: [Json] Go JSON parser ignores the case of mem… Anders Rundgren
- Re: [Json] Go JSON parser ignores the case of mem… Rob Sayre
- Re: [Json] Go JSON parser ignores the case of mem… John Cowan
- Re: [Json] Go JSON parser ignores the case of mem… Manger, James
- Re: [Json] Go JSON parser ignores the case of mem… Anders Rundgren
- [Json] JSON in Web Pages. Was: Go JSON parser ign… Anders Rundgren
- Re: [Json] JSON in Web Pages. Was: Go JSON parser… Anders Rundgren