Re: [Json] Go JSON parser ignores the case of member names

"Manger, James" <> Thu, 10 March 2016 04:56 UTC

Return-Path: <>
Received: from localhost (localhost []) by (Postfix) with ESMTP id D44D312DDB6 for <>; Wed, 9 Mar 2016 20:56:17 -0800 (PST)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -2.62
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 ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id NI-IzbMDfcAs for <>; Wed, 9 Mar 2016 20:56:15 -0800 (PST)
Received: from ( []) by (Postfix) with ESMTP id DACD012DDB4 for <>; 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 ([]) by with ESMTP; 10 Mar 2016 15:55:48 +1100
X-IronPort-AV: E=McAfee;i="5700,7163,8099"; a="85209405"
Received: from ([]) by with ESMTP; 10 Mar 2016 15:55:48 +1100
Received: from ([]) by ([fe80::91f4:aabc:bfb0:95c4%16]) with mapi; Thu, 10 Mar 2016 15:55:48 +1100
From: "Manger, James" <>
To: John Cowan <>, Rob Sayre <>
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: <>
References: <> <> <> <> <> <>
In-Reply-To: <>
Accept-Language: en-US, en-AU
Content-Language: en-US
acceptlanguage: en-US, en-AU
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Archived-At: <>
Cc: "" <>
Subject: Re: [Json] Go JSON parser ignores the case of member names
X-Mailman-Version: 2.1.17
Precedence: list
List-Id: "JavaScript Object Notation \(JSON\) WG mailing list" <>
List-Unsubscribe: <>, <>
List-Archive: <>
List-Post: <>
List-Help: <>
List-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" <>gt;. 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