Actions
Bug #16825
closedJSON#generate gives invalid json string
Description
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.
require 'json'
my_hash = { key: "symbol", "key" => "string" }
JSON.generate(my_hash) #=> "{\"key\":\"symbol\",\"key\":\"string\"}"
Expected:
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.
Actions
Like0
Like0Like0Like0