Andrek
Andrek

Reputation: 105

Ruby how to parse a Json file with Array keys

I'm trying to get a Hash from a Json file that has Array Keys, but its return each array key like string.

hash = {[10, 10] => [[1, 1], [5, 5]]}
p JSON.parse(hash.to_json) #=> {"[10, 10]" => [[1, 1], [5, 5]]}

Maybe i should use YAML, any idea?

Upvotes: 0

Views: 159

Answers (1)

Jörg W Mittag
Jörg W Mittag

Reputation: 369428

There are three slightly different versions JSON, as specified by

While there are small differences between the three, one thing they all agree on: Object Keys are Strings. Always.

In other words, "a Json file that has Array Keys" cannot possibly exist. Whatever you have, it is either a JSON file, but then it cannot have Array Keys, or it is simply not a JSON file.

Upvotes: 3

Related Questions