Wow, I didn't realise until now that Unmarshal does case-insensitive 
matching:
https://play.golang.org/p/wddrcakLvr_Q
The documentation <https://pkg.go.dev/encoding/json#Unmarshal> says it 
prefers exact match over case-insensitive, but example 3 contradicts that.  
It seems to be last-match that wins.

Regardless of any X-Y issue, this seems broken to me. If I define a 
particular API, I want to enforce that it's being used in the way that I 
defined.  Accepting arbitrary variations just stores up problems for the 
future.
Case-insensitivity can open up its own issues: e.g. 
https://www.theregister.com/2021/09/22/macos_rce_flaw/

As a workaround, you could use a YAML decoder to decode JSON.  JSON is a 
subset of YAML.  If you don't want to accept YAML as well, then you might 
have to decode it twice: once to confirm that it's structurally JSON, and 
again to extract the data.
https://play.golang.org/p/XHlvdlyQqMI

On Thursday, 23 September 2021 at 21:53:23 UTC+1 xav...@gmail.com wrote:

> Hi Aaron,
>
> I'm not aware of a JSON library that fits your needs, but there might be 
> an XY Problem <https://xyproblem.info/> going on here. What problem are 
> you having trouble solving with encoding/json that lead you to this 
> solution?
>
> On Thu, Sep 23, 2021 at 11:23 AM 'Aaron' via golang-nuts <
> golan...@googlegroups.com> wrote:
>
>> Hi all
>>
>> Anyone know of a JSON package (or other solution) which is case-sensitive 
>> when decoding - and is also mature, simple, and parses into a struct?
>> I've looked at a few open-source packages, but the ones I've found seem 
>> to be focused on performance, or allowing you to access the JSON in 
>> different ways, or require code-generation, or something.
>> Really I just want a drop-in replacement for encoding/json that is case 
>> sensitive.
>> Wondering about forking the package myself... but obviously don't want to 
>> do that if there's an existing solution.
>>
>> Thanks
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/a3d25416-2490-4719-a38c-9f6a43008184n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/a3d25416-2490-4719-a38c-9f6a43008184n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9ea378ee-3705-4a78-8764-01857694ffcan%40googlegroups.com.

Reply via email to