From: shyouhei@... Date: 2020-05-03T07:47:37+00:00 Subject: [ruby-core:98126] [Ruby master Bug#16825] JSON#generate gives invalid json string Issue #16825 has been updated by shyouhei (Shyouhei Urabe). Actually it is not an _invalid_ JSON in any sense. RFC 8259 section 4 explicitly allows such duplicated names: https://tools.ietf.org/html/rfc8259#section-4 ---------------------------------------- Bug #16825: JSON#generate gives invalid json string https://bugs.ruby-lang.org/issues/16825#change-85369 * Author: definitely_not_a_bot (Definitely Not A Bot) * Status: Third Party's Issue * Priority: Normal * ruby -v: 2.6.5 * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- Hello Guys! First of all, thank you for working on the Ruby language. I observed a peculiarity while playing around with `JSON#generate`. When hash contains keys of the same word/literal but as symbol and string in the same hash, the `JSON#generate` creates JSON string with a duplicate key. ```ruby require 'json' my_hash = { key: "symbol", "key" => "string" } JSON.generate(my_hash) #=> "{\"key\":\"symbol\",\"key\":\"string\"}" ``` Expected: ```ruby JSON.generate(my_hash) #=> "{\"key\":\"string\"}" ``` I am new to ruby, so not sure if this right platform to report this observation. I do feel like the current result is the desired result but found it little odd behavior. Please do close this issue if, it is not the right platform for the issue or it is the intended behavior. -- https://bugs.ruby-lang.org/ Unsubscribe: